Xcode shared Test Plan across schemes causes each target to build

1.6k views Asked by At

I have a simple Test Plan (with a single configuration) in my Xcode project which I am switching over to because I have multiple schemes for different app targets in my project but the tests are shared (as in they are not specifically limited to one target in terms of relevance, though only one host application was possible). I would like to have one Test Plan for now for all the targets, but when I created the Test Plan and added it to each scheme, and then ran the tests, I can clearly see that every target has been built. The length of time it takes to build and run the tests is thus increased incrementally for each target I add. The 2019 WWDC video on Test Plans clearly says they can be shared across multiple schemes but doesn't say much more than that.

Is this how it's supposed to behave? Or is there a way to share a test plan between schemes but have it only build the active target that's being tested?

EDIT: note, running tests locally as well as in automated CI, so need a solution that works for both.

I'm actually not sure if it's building multiple targets because of the test plans, because only a few targets are showing in builds while there are (although it could be that Xcode is optimizing and skipping redundant building since each of the other ones is pretty much the same as one of ones that is building).

1

There are 1 answers

0
shim On BEST ANSWER

Aha! It was not about Test Plans at all but rather dependencies inside the individual test bundle. Realized this when I went back before I switched to Test Plans and notice a couple of the targets were still building for a single test bundle.

Click on the scheme in Xcode project settings, go to Build Phases tab, then under dependencies check what targets are there.

In my case one of my test bundles had two targets, and the other test bundle (for UI tests) had a third target.

Even though my Test Plan had the UI tests disabled, I guess it was still building all the dependencies. Cleaning that up fixed the build issue I was having!