Ios 快速/灵巧

Ios 快速/灵巧,ios,unit-testing,integration-testing,kif,Ios,Unit Testing,Integration Testing,Kif,我正试图让iOS的和很好地结合在一起,这样我就可以使用QuickSpec进行KIF测试 我的测试目前如下所示: class HomeSceenSpec: QuickSpec { override func spec() { describe("Home screen") { it("should have a failing test") { let tester = self.tester()

我正试图让iOS的和很好地结合在一起,这样我就可以使用QuickSpec进行KIF测试

我的测试目前如下所示:

class HomeSceenSpec: QuickSpec {

    override func spec() {
        describe("Home screen") {
            it("should have a failing test") {
                let tester = self.tester()
                tester.waitForViewWithAccessibilityLabel("Blah")
            }
        }
    }
}
文本“Blah”不存在,测试应该失败<代码>failWithException:stopTest:正在被调用,但它不会引发异常或导致QuickSpec测试失败


如何集成这两种技术?

看起来可能存在
failWithException:stopTest:
调用
recordFailureWithDescription:infle: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)
        }
    }
}

我们刚刚发布了
kifquick
cocoapod,这应该会有所帮助,请参见:

以下是规范的一个示例:

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()
                }
            }
        }
    }
}

如果不使用敏捷,也可以使用
XCTFail()
而不是
fail()
。两个函数的参数相同。(
fail
最终在引擎盖下调用
XCTFail
)。