【问题标题】:KIF and Quick/NimbleKIF 和 Quick/Nimble
【发布时间】:2015-03-28 09:17:10
【问题描述】:

我正在尝试让 iOS 的 KIFQuick/Nimble 很好地配合使用,这样我就可以使用 QuickSpecs 进行我的 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 测试失败。

如何整合这两种技术?

【问题讨论】:

    标签: ios unit-testing integration-testing kif


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      看起来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)
              }
          }
      }
      

      【讨论】:

      • 如果您不使用 Nimble,也可以使用 XCTFail() 而不是 fail()。两个函数的参数相同。 (fail 最终在后台调用XCTFail)。
      猜你喜欢
      • 1970-01-01
      • 2018-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多