Reputation: 3508
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.
Upvotes: 53
Views: 13705
Reputation: 1915
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.
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
Upvotes: 2
Reputation: 13993
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.
Upvotes: 1
Reputation: 89
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()
Upvotes: 0
Reputation: 9352
When you add a new test, save the file (Cmd+S) and the diamond will appear (verified on Xcode 7.3)
Upvotes: 1
Reputation: 2702
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!!.
Upvotes: 4
Reputation: 21808
For me it was enough to select Product->Test
and wait a bit. When the tests just start running all the diamonds become available
Upvotes: 2
Reputation: 36447
Below are few solution for this issue :
Wait for sometime. It takes time to load diamond sometimes. Navigate between different files and then move to same test-case it should appear.
Clean project, Clean build folder and even delete derived data content. Check this how to delete derived data safely.
Quit Xcode and open it again.
Make sure that your test-case name begins with testFunc_Name
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.
Upvotes: 9
Reputation: 511736
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:
Upvotes: 3
Reputation: 926
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.
Upvotes: 1
Reputation: 23976
For me the fix was to prefix all method with 'test'
i.e.
func arrayResponseCall()
should be:
func testArrayResponseCall()
Upvotes: 24
Reputation: 434
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")
}
Upvotes: 6
Reputation: 3508
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.
Upvotes: 56
Reputation: 1129
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.
Upvotes: 14
Reputation: 4809
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.
Upvotes: 2
Reputation: 143134
(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.
Upvotes: 3