Xcode fails to discover tests, missing gutter test diamonds

A couple of days ago Xcode stopped loading our tests into the test navigator. Additionally our test class files stopped showing the gutter test diamonds. We can still run the tests using CMD+U and after a successful run every test case shows up in the test navigator. But, the test diamonds don't return which implies that Xcode doesn't see these files as tests.


So, it seems that something in our project has broken Xcode's test case indexing.


The project is mainly Obj-C with an growing Swift part. Our test suite contains ~6000 unit tests derived from XCTestCase. This problem is reproducible on El Capitan 10.11.3, both when using Xcode 7.2.1 and Xcode 7.3 beta 5.


We've tried all the usual measures for when dealing with bad Xcode state:


  • Clean building.
  • Deleting derived data.
  • Deleting ~/Library/Caches/com.apple.dt.XCode


Is this a known issue? Can anyone help us understand how Xcode discovers the tests so that we could fix the issue with our project?


Update:

When observing what happens in Console.app when opening Xcode we see the following lines:



17/03/16 11:44:44,717 Xcode[89856]:  IDEIndexingClangInvocation: Failed to save PCH file: /Users/johannth/Library/Developer/Xcode/DerivedData/MyApp-fmkkuqtykhsstrezzmhrfiedrpcu/Index/PrecompiledHeaders/UnitTests-Prefix-dvmyiewguqjpnbflmvoybdjdec.pch.pch
17/03/16 11:44:53,954 sourcekit-serv[89989]: [1:hashFileReference:8599: 2.1299] failed to stat file: <imports> (No such file or directory)


We actually see a lot of the latter error. By running git bisect we've pinpointed that setting `DEFINE_MODULE=YES` introduced the issue and reverting it to `DEFINE_MODULE=NO` fixes it with various weird side effects. The .pch file for UnitTests only contains the standard Foundation and UIKit imports so I don't think there is anything directly in it which breaks the indexing.


Anyone have any idea how to better understand the console logs from Xcode?

Post not yet marked as solved Up vote post of johannth Down vote post of johannth
14k views

Replies

I've encountered this while running UI tests on a device. When it happens I tend to just powercycle the test device, or unplug/replug it.

We have much the same issue. Modules has completely broken the indexer for us. Not only for unit tests but for autocomplete as well.

We have two module frameworks that we build and use.


Also, we have a subclasses of XCTestCase that we use, and that seems to make all of the tests turn into RuntimeTests (which are shown with a different icon (rT) and and challenged in many ways (can't click on them to open them, can't run them, etc).


The only way to see our 2000 or so tests is to run a test build then they show up as normal tests (sometimes, most often we need to Full Clean first, then rebuild, then run the full suite of tests). This makes iteration on single tests impossible.


Any insight into the failure of the indexer to properly identify unit tests would be appreciated.


When I turn on: defaults write com.apple.dt.xcode IDEIndexingClangInvocationLogLevel 3


I get flooded with diagnostic errors in the console, most of which indicate that the indexer can't seem to index our `DEFINE_MODULE=YES` frameworks.

We see it also. Don't have a workaround.

Try deleting the project's derived data ie. Window->Projects

Close xcode, reopen, and you should see the project being indexed.

This is still happening on Xcode 10.2, THREE years later. It's incredible that Apple still hasn't fixed it, so disappointing.

I just had this issue happen to me and solved it.


I went the Xcode Navigator by command-6. Seeing all of my tests listed there, but grayed out, I simply did a control-click on the Test class and from the popup navigation options selected the 'Enable Tests', and then ran the first test in the list. My test started building right away and then it ran. The diamonds appeared right after that process.

You are a genius, thank you! 🙂

This should be marked as the answer, worked like a charm on Xcode 11.0

Thank you @pjbrockmann! That's perfect

Restarting Xcode did the trick to me

begin your function name with 'test' and it should pick it up

I fixed it by launching unit test on simulator instead of real device. All the diamonds re-appeared. Worked like a charm