MobileNativeFoundation / rules_xcodeproj

Bazel rules for generating Xcode projects.
MIT License
519 stars 82 forks source link

Bug: Unit Tests with multiple deps are not showing tests in Xcode.IDETestNavigator #3064

Open themz opened 1 month ago

themz commented 1 month ago

Description

Hello, I am trying to use ios_unit_test with multiple static libraries as dependencies. The test code is located in these static libraries. The issue I am facing is that there is a missing reference to the particular tests in the Xcode Test Navigator.

In the attached project, when I run the tests using Bazel, the results look good: all unit tests are executed.

However, when I open Xcode after generating the project, no tests are visible in the Xcode Test Navigator.

before_run

If I run all tests using Cmd+U or click on "All Tests" in the Xcode Test Navigator, the tests are detected at runtime:

after_run

However, if I try to run only one test, no tests are executed, but this empty execution is reported as successful.

When I keep only one dependency for ios_unit_test and regenerate the project, everything works as expected.

only_one_deps

I would be happy to work on this, but I need some help with direction. So far, I believe the issue occurs during the index build. I have tried to find the difference in how apple_rules handles one vs. multiple dependencies for unit tests, but I have not found any differences yet.

simple-unit-test-example.zip

Reproduction steps

In the attached project run

  1. bazel run //:a_and_b_xcodeproj
  2. Open Xcode Test Navigator

Expected behavior

To be able to see and run any particular unit test from Xcode test navigator.

rules_xcodeproj version

2.5.2

Xcode version

15.4 (15F31d)

Bazel version

7.2.1

rules_apple version

3.6.0

rules_swift version

2.1.1

Additional information

No response

brentleyjones commented 1 month ago

This is expected. If the test has multiple deps, then rules_xcodeproj can’t merge the libraries into the top-level target. We can’t merge multiple same-language targets into a top-level target because they have different compiler flags, in particular different module names. And when the top-level target doesn’t have the source files associated with it, then it Xcode index the tests and doesn’t show the gutter diamonds or the tests in the navigator. After one run of the tests though Xcode sees them as dynamic tests and shows them.