Update build schema to force you to select correct target when building tests #1927
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📲 What
Force you to select the correct build schema when running tests via Xcode.
🤔 Why
Say you have an arbitrary target selected, and you try and run some tests by hitting the play button. In this example, I'm trying to run a test in
Library-iOS-Tests
, and I have theKickstarter-iOS
target selected, because I was running the app.You might be treated to this linker error. However, look closely - why is it trying and failing to build
KsApiTests
?This is odd - while
Library-iOS
depends onKsApi
,Library-iOS-Tests
does NOT depend onKsApiTests
.Looking into the dependency graphs, and it looks like the app is trying to build
Kickstarter-iOS
, and then as part of that, it includedKsApiTests
. That is also odd. First, why is it buildingKickstarter-iOS
instead of justLibrary-iOS
andLibrary-iOS-Tests
? And for that matter, why wouldKickstarter-iOS
(the app) depend onKsApiTests
(a test bundle)?It turns out the answer was in the schema.
Kickstarter-iOS
was set up so that it was associated with all of our tests, and it would try to run them (all!) if it was selected as the schema when you run any tests. As far as I can tell, this led to general Xcode and linker strangeness, until you either swapped targets or ran a full project clean.The solution was to uncheck all those test boxes. Now, when you try to run a test in the same scenario, you get this handy pop-up that forces you to swap to the correct test target: