facebookarchive / ios-snapshot-test-case

Snapshot view unit tests for iOS
MIT License
2.66k stars 253 forks source link

0 out of 0 tests passed, Inheritance from FBSnapshotTestCase vs XCTestCase #229

Closed alextakahashi closed 7 years ago

alextakahashi commented 7 years ago

I'm having a problem running tests using the FBSnapshotTestCase. Working on a simple proof of concept I was able to run FBSnapshotTestCase without any problems. Once I integrated this with my current project, I am not able to run tests instead it simply says I've run 0 out of 0 tests.

Code Excerpt w/ FBSnapshotTestCase

import FBSnapshotTestCase

class FBSnapshotTesting: FBSnapshotTestCase {

    override func setUp() {
        super.setUp()
        recordMode = true
    }

    override func tearDown() {
        super.tearDown()
    }

    func testBlueSquare() {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
        view.backgroundColor = UIColor.blue
        FBSnapshotVerifyView(view)
        FBSnapshotVerifyLayer(view.layer)
    }

    func testShouldFail() {
        XCTAssert(false)
    }

}

Terminal Output

Test Suite 'Selected tests' started at 2017-06-12 13:55:09.011

Test Suite 'ProjectTests.xctest' started at 2017-06-12 13:55:09.012

Test Suite 'ProjectTests.xctest' passed at 2017-06-12 13:55:09.012.
     Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.000) seconds

Test Suite 'Selected tests' passed at 2017-06-12 13:55:09.012.
     Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds

Looking at the log, I can see that the tests are simply not being run. Debugging doesn't work, setUp() is not even being called.

I've narrowed down the problem to inheriting from XCTestCase vs FBSnapshotTestCase. If I change the class inheriting to XCTestCase, the Test Case runs as normal (minus the functionality of FBSnapshotTestCase).

Code Excerpt w/ XCTestCase

import FBSnapshotTestCase

class FBSnapshotTesting: XCTestCase {

    override func setUp() {
        super.setUp()
//        recordMode = true
    }

    override func tearDown() {
        super.tearDown()
    }

    func testBlueSquare() {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
        view.backgroundColor = UIColor.blue
//        FBSnapshotVerifyView(view)
//        FBSnapshotVerifyLayer(view.layer)
    }

    func testShouldFail() {
        XCTAssert(false)
    }

}

Terminal Output

Test Suite 'Selected tests' started at 2017-06-12 14:18:53.504

...

Test Suite 'FBSnapshotTesting' failed at 2017-06-12 14:18:53.508.
     Executed 2 tests, with 1 failure (0 unexpected) in 0.002 (0.003) seconds

Test Suite 'ProjectTests.xctest' failed at 2017-06-12 14:18:53.508.
     Executed 2 tests, with 1 failure (0 unexpected) in 0.002 (0.004) seconds

Test Suite 'Selected tests' failed at 2017-06-12 14:18:53.508.
     Executed 2 tests, with 1 failure (0 unexpected) in 0.002 (0.004) seconds

Now, this code is able to run as expected. Does anyone have any leads or can provide some help?

Notes

alextakahashi commented 7 years ago

Update! So I eventually got it to work, I ended up doing Copy Files to Frameworks as described in this post Carthage Headaches