Reputation: 1282
I've been troubleshooting this for a few days and am all out of ideas.
I was using unit testing in Xcode and it was working great. All of a sudden Xcode no longer recognizes my tests. If I go to the tests panel, it shows that I have zero tests. I actually have 13.
The ability to run individual tests or certain classes is now gone. It doesn't show the buttons in the gutter of the editor area.
I am still able to run all of my tests if I click the button to the right of the "0 Tests" in the test panel. When I click this it then starts populating all of my tests and they still appear to run properly. However, now that the tests are shown in the tests panel, they still are not linked to my tests in the classes. Usually if you click on a test, it will take you to it in the file where it lives. This functionality is gone.
I opened up another old project I had saved and it is having the same issue. However, I started a new project and it is working just fine and is showing no signs of any problems.
Any ideas as to what I may have done? I've found a few other threads out there about this on here, but none of them have gotten any helpful responses and are at least a number of months old. Hoping maybe creating a new thread will bump this again.
My next thought is to start the project over again and copy my files over. Not sure what else to do.
Upvotes: 7
Views: 3719
Reputation: 1616
I had the same problem, and all my methods have the test prefix.
So, the problem is with Xcode indexing, as some targets could see all tests and some could not. To create a fresh index, follow these steps:
~/Library/Developer/Xcode/DerivedData/
rm -rf YourProjectDir
Done! When you open the project, wait for reindexing, and the tests should appear as usual.
Upvotes: 13
Reputation: 501
All test method begin with "test":
func testValidateStudent()
{
// your code
}
make sure that your test methods begin with "test".
Upvotes: 11
Reputation: 4755
The test markers seem to be shown depending on the current scheme and whether the tests match that scheme.
(I tested that in Xcode 11, not sure about the time, when the question was asked originally. In my case I had to clear derived data to make the test markers appear again at all and then noticed the scheme dependency. The problem may have been triggered when I added a test with the same name to two different test targets.)
See screenshot below for a project with iOS and tvos targets. For instance the tests for the iOS target (on the left hand side in screenshot) will only be marked when the iOS target / scheme is selected. The tvos tests (on the right hand side in screenshot) will not show the markers in that case. Switching the scheme (red mark in top left) will hide the iOS test markers in the file on the left and show the tvos test markers in the file on the right.
Upvotes: 2