3

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?

4

2 回答 2

5

看起来failWithException:stopTest:调用可能有问题recordFailureWithDescription:inFile:atLine:expected:。(这种方法有很多混乱)。

我找到的解决方案是在 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)
        }
    }
}
于 2015-01-29T21:30:50.230 回答
2

我们刚刚发布了KIF-Quickcocoapod,应该会有所帮助,请参阅:

http://cocoapods.org/pods/KIF-Quick

这里是规范的一个例子:

import Quick
import KIF_Quick

class LoginSpec: KIFSpec {
    override func spec() {
        describe("successful login") {
            context("home view") {
                beforeEach() {
                    tester().navigateToLoginPage()
                }

                it("should open Welcome page") {
                    viewTester().usingLabel("Login User Name").enterText("user@example.com")
                    viewTester().usingLabel("Login Password").enterText("thisismypassword")
                    viewTester().usingLabel("Log In").tap()
                    viewTester().usingLabel("Welcome").waitForView()
                }

                afterEach() {
                    tester().returnToLoggedOutHomeScreen()
                }
            }
        }
    }
}
于 2016-12-26T06:01:09.420 回答