Xcode 6 Editor doesn't recognize unit tests

IosUnit TestingIdeXcode6Xctest

Ios Problem Overview


I have a problem that the Xcode IDE 6 doesn't detect my swift unit test cases correctly. When I run the unit tests, all tests were executed.

But in the IDE while editing the unit tests aren't recognized. I have to run the whole unit test suite in order to run a single test.

I couldn't figure out how I avoid this glitch.

enter image description here

Ios Solutions


Solution 1 - Ios

Problem is solved. All I have to do is to launch the "Window -> Projects" window and delete the "Derived Data. After indexing all tests are working.

In the meanwhile apple is fixing the bugs in the Xcode 6.3 editor bit by bit.

Solution 2 - Ios

For me the fix was to prefix all method with 'test'

i.e.

func arrayResponseCall() 

should be:

func testArrayResponseCall()

Solution 3 - Ios

The "fix" for me was to add a new test. I made up some nonsense:

func testThatNothing() {
    XCTAssertTrue(true, "True should be true")
}

When I ran the tests again, all the tests in that file were recognized by the editor. I deleted the bogus test and it's all still fine. Unfortunately I had to do this in each file, but at least it works. Hope this helps someone.

Solution 4 - Ios

Below are few solution for this issue :

  1. Wait for sometime. It takes time to load diamond sometimes. Navigate between different files and then move to same test-case it should appear.

  2. Clean project, Clean build folder and even delete derived data content. Check this how to delete derived data safely.

  3. Quit Xcode and open it again.

  4. Make sure that your test-case name begins with testFunc_Name

  5. Sometimes your test-case file may contain function other than test-case. In such scenario diamond symbol doesn't appears. Remove such function.

In my case 1, 3 and 5 solution often worked for me.

Solution 5 - Ios

For me , I need to add Tests to below here enter image description here

Solution 6 - Ios

I had the same problem too. Just make sure each of your test cases has some sort of XCTAssert() Statements.

func testSomething(){
     XCTAssert(true, "Pass")
}

Solution 7 - Ios

Make sure the test case name begins with "test" followed by any name you want and build(cmd+B) the project.the diamond will appear!!.

Solution 8 - Ios

(Since your comment indicates you're still having this problem after a week, this might not help you, but…)

I ran into this problem where adding a new (Swift) test in 6.1 wouldn't make it show up in the "Test Navigator" or the scheme editor -- restarting Xcode fixed the problem and now I can run the tests individually.

Solution 9 - Ios

Xcode 7

My full answer is here.

In Xcode 7 getting Unit Testing set up is a little easier than in Xcode 6 (no need to annotate class and methods as public). Use @testable before the import of the class name.

import XCTest
@testable import MyProject

class MyClassTests: XCTestCase {

    func testMyMethod() {
        
        let myClass = MyClass()
        let sum = myClass.addTwoNumbers(1, 2)
        
        XCTAssertEqual(sum, 3)
    }
}

In your class you don't have to do anything special.

class MyClass {

    func addTwoNumbers(a: Int, b: Int) -> Int {
        return a + b
    }
}

It is possible you may also have to set "Defines Module" under Packaging to YES for your app's Build Settings.

See also these answers:

Solution 10 - Ios

I had a similar error (though in Objective C, not swift). If I added a new test method to the class, the new method wouldn't show up in the test navigator nor would it be executed when I ran the whole bundle. I also wouldn't get those dots in the side bar next to each method that, if clicked, would run just one test method.

The only thing fixed my problem was deleting my whole test class (saving its contents elsewhere temporarily) then recreating the test class and (perhaps more carefully?) setting the build settings all over again.

Solution 11 - Ios

For me it was enough to select Product->Test and wait a bit. When the tests just start running all the diamonds become available

Solution 12 - Ios

In my case I had a reference to an old test target which was causing the issue, so I got rid of the missing target and clean the solution and then my test cases were working fine.

Xcode test Schemes

Also make sure that the test methods you create should always start with the keyword "test" else Xcode won't be able to identify the test methods an example of the same is

func test_getPhotos_With_Good_Request_Returns_PhotoCollection(){

    //ARRANGE
    
    //ACT

   //ASSERT
           
}

Hope it helps

Solution 13 - Ios

Sometimes all you need to do is wait for Xcode to finish indexing all your files. For large projects my unit test navigator view is frequently empty until it finishes.

Solution 14 - Ios

When you add a new test, save the file (Cmd+S) and the diamond will appear (verified on Xcode 7.3)

Solution 15 - Ios

Here is what worked for me. Even though the unit test says it has 0 tests available, I clicked play, and then it ran through all 4 tests and then it showed.

enter image description here

Solution 16 - Ios

I solved my problem just turning the private methods into public.

So, if this is the same problema you're facing, switch:

private func testString()

to:

public func testString()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChaosSpeederView Question on Stackoverflow
Solution 1 - IosChaosSpeederView Answer on Stackoverflow
Solution 2 - IosAntoineView Answer on Stackoverflow
Solution 3 - IosReidView Answer on Stackoverflow
Solution 4 - IosJayprakash DubeyView Answer on Stackoverflow
Solution 5 - IosStephen ChenView Answer on Stackoverflow
Solution 6 - IosErnest HanView Answer on Stackoverflow
Solution 7 - IosAkila WasalaView Answer on Stackoverflow
Solution 8 - IosSophie AlpertView Answer on Stackoverflow
Solution 9 - IosSuragchView Answer on Stackoverflow
Solution 10 - IosOlivia StorkView Answer on Stackoverflow
Solution 11 - IosAndrey ChernukhaView Answer on Stackoverflow
Solution 12 - IosNSDumbView Answer on Stackoverflow
Solution 13 - IosAri BraginskyView Answer on Stackoverflow
Solution 14 - IosMike TaverneView Answer on Stackoverflow
Solution 15 - IosScottyBladesView Answer on Stackoverflow
Solution 16 - IosAlcivanioView Answer on Stackoverflow