首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS UI单元测试(XCode7)

iOS UI单元测试(XCode7)
EN

Stack Overflow用户
提问于 2015-07-21 00:43:56
回答 1查看 944关注 0票数 1

我对苹果在其XCode7测试版中发布的新的UI单元测试方案感到有点困惑。我认为这是一个很棒的想法,但我有几个问题。

这是我有的一种测试方法。

代码语言:javascript
复制
func testMetricsProperties() {
    // Used some of the metrics for testing for reference

    let app = XCUIApplication()
    app.scrollViews.descendantsMatchingType(.Unknown).containingType(.StaticText, identifier:"rim").childrenMatchingType(.Button).element.tap()
    app.textFields["_XCUI:Secure"].typeText("")
    app.typeText("\r")
    app.buttons["dash metrics"].tap()

    let element = app.descendantsMatchingType(.Unknown).containingType(.Image, identifier:"darkBackground.png").childrenMatchingType(.Unknown).element.childrenMatchingType(.Unknown).elementBoundByIndex(1).childrenMatchingType(.Unknown).element.childrenMatchingType(.Unknown).element
    let offPlanRevenue = element.childrenMatchingType(.Unknown).elementBoundByIndex(0).staticTexts["OFF PLAN REVENUE"]
    offPlanRevenue.tap()

    XCTAssert(offPlanRevenue.exists);
    XCTAssertEqual(offPlanRevenue.value as! String, "");
}

然而,在接下来的测试方法中,似乎我必须重新加载整个应用程序,

代码语言:javascript
复制
let app = XCUIApplication()
    app.scrollViews.descendantsMatchingType(.Unknown).containingType(.StaticText, identifier:"im").childrenMatchingType(.Button).element.tap()
    app.textFields["_XCUI:Secure"].typeText("")
    app.typeText("\r")
    app.buttons["dash metrics"].tap()
}

有什么我可以避免的吗?如果我试图在整个套件上运行完整的测试,这可能会很麻烦。

EN

回答 1

Stack Overflow用户

发布于 2015-07-21 03:02:28

我相信您正在寻找的是使用setUp()tearDown()方法。在每个测试方法之前调用setUp(),在类的每个测试方法之后调用tearDown()

代码语言:javascript
复制
override func setUp() {
    super.setUp()
      // Put setup code here. This method is called before the invocation of each test method in the class.
  }

  override func tearDown() {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    super.tearDown()
  }

使用这些方法可以在测试方法之间恢复到应用程序的原始状态。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31521916

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档