Running a Test in Xcode Compiles the Wrong Target
When running tests, you (mostly me and QA but you one day) may have noticed that Xcode will sometimes fail to compile tests, yelling about missing OurAwesomeProject-Swift.h.
“Oh, I must have configured something wrong,” you say.
“Wait I just redid everything and it still happens,” you say.
“What the fuck is Xcode smoking,” you say.
After a very very long time debugging this, I am happy to announce that Xcode is, indeed, a little fucked up.
TL;DR: Don’t use this little tease of a button:
That is a black diamond. User beware. You will fall and die. Instead, please use the test navigator:
And run your tests from there. TRUST ME. (It works).
“But shouldn’t Xcode know which target you want to run by looking at your currently selected Scheme which has that target selected like it does for everything else?”
YES. IT SHOULD.
It looks like Xcode is confused because one test class is part of two different targets (AcidIntegrationTests and DeviceIntegrationTests). When you go to the Test Navigator the hierarchy is clear so it seems like it knows which one to run. When you run it from the class it looks like it uses its patented algorithm of Doing The Wrong Thing[TM] and compiles the wrong target.
Why do we need two targets you ask? Another fun historical digression: Since media code can not compile for simulator so we have OurAwesomeProjectSim and OurAwesomeProject targets. This means two different host applications, which implies two different testing targets. Everything(including Mega Man)X2.