Unable to add TestHost app target dependency from another project

Hello Tuist community :slight_smile:
Hopefully this is the right place to raise and discuss this!

We are moving our project to Tuist, and came across an issue which currently blocks us from continuing -

We have several projects that need a test host to run the tests. Rather than adding a test host target to each, we created a TestHost project with an app target, which is shared between the different projects. This project is used by manually dragging it to the project in which its used, then adding it to the `Target Dependencies" build phase.

We would like to do something similar with the Tuist configuration. However, simply adding something like:

    .project(target: "TestHost", path: "../TestHost"),

To the relevant target’s dependencies seems to do nothing. The path and name are OK, and there are other dependencies - it just seems like adding an app target from another project as a dependency doesn’t work. Adding it manually after generating the project (by dragging the TestHost project to be under the project, and manually adding it to Target Dependencies) works fine. Also, I would like to mention that the build settings of TEST_HOST and BUNDLE_LOADER are set as expected, so we can narrow the issue to the addition of the dependency.

I do see some fixtures in the Tuist repo with app target as a dependency, but as much as I could tell - none where the target is on another project.

We would love to hear any insights you have about this issue, and/or guidance as to where to look in the code (e.g. - is there a place in the code where you would expect this to be added as a dependency, but it’s not? What are some classes/areas in the code that seems most relevant to this?).

Thank you, and have a lovely rest of the day! :pray:

Hey @Tamar!

Yes, you are right – an app is considered to be a host for a unit tests target only when it’s defined in the same project. The logic for that is here: tuist/Sources/TuistCore/Graph/GraphTraverser.swift at 75c7eedcd8970eb9c03ed6ad3eb1ae5ebaa97dbb · tuist/tuist · GitHub

I’m not aware of why we’d need to consider only local target dependencies. I believe that method can also search through target dependencies that are defined in a different project.

Would you want to go ahead and open a PR? We can continue the conversation there.

Thank you very much! I would gladly make those changes and open a PR :muscle:

Other than this (and probably something similar for TEST_TARGET_NAME), there seem to be two other things that needs to be done:

  1. Add a reference to the test host project under the “Products” group - I have yet to find the exact place in which it should be added
  2. Add the target as a dependency - I think what’s missing there is under TargetGenerator → generateTarget: since the test host app target is not linked with or embedded, and generateTargetDependencies only takes the local dependencies into account, I think app targets that aren’t local falls between the cracks, so it should probably be added there (once there’s a file reference to it)

If you have any pointers here or I’m missing something - would be appreciated!