iosunit-testingintegration-testingkif

KIF and Quick/Nimble


I'm trying to get KIF and Quick/Nimble for iOS playing together nicely, so I can use QuickSpecs for my KIF tests.

My test currently looks like this:

class HomeSceenSpec: QuickSpec {

    override func spec() {
        describe("Home screen") {
            it("should have a failing test") {
                let tester = self.tester()
                tester.waitForViewWithAccessibilityLabel("Blah")
            }
        }
    }
}

The text 'Blah' doesn't exist and the test should fail. failWithException:stopTest: is being called but it isn't raising an exception or causing the QuickSpec test to fail.

How do I integrate these two technologies?


Solution

  • It looks like there may be an issue with failWithException:stopTest: calling recordFailureWithDescription:inFile:atLine:expected:. (There's a good deal of swizzling going on with that method).

    The solution I came to was to create a category/extension on QuickSpec:

    import Quick
    import Nimble
    import KIF
    
    extension QuickSpec {
    
        func tester(_ file : String = __FILE__, _ line : Int = __LINE__) -> KIFUITestActor {
            return KIFUITestActor(inFile: file, atLine: line, delegate: self)
        }
    
        func system(_ file : String = __FILE__, _ line : Int = __LINE__) -> KIFSystemTestActor {
            return KIFSystemTestActor(inFile: file, atLine: line, delegate: self)
        }
    
        override public func failWithException(exception: NSException!, stopTest stop: Bool) {
            if let userInfo = exception.userInfo {
                fail(exception.description,
                    file: userInfo["SenTestFilenameKey"] as String,
                    line: userInfo["SenTestLineNumberKey"] as UInt)
            } else {
                fail(exception.description)
            }
        }
    }