使用 TDD 在 Swift 中进行性能测试

Performance testing in Swift using TDD

刚刚在 Swift 中学习 Test Driven Development。我创建了一个 class,它是 "ProjectNameTests" 组中 XCTestCase 的子 class。

    class BasicFunctionTest: XCTestCase {

        var values : [Int]?
        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()
        }

        func testExample() {
            // This is an example of a functional test case.
            XCTAssert(true, "Pass")
        }

        func testPerformanceExample() {
            // This is an example of a performance test case.
            self.measureBlock() {
                // Put the code you want to measure the time of here.
                for i in 1...100000{

                    println("ok i need to know the time for execution")


                }
            }
        }
}

我想对这些方法进行性能测试

func testPerformanceExample() {
    // This is an example of a performance test case.
    self.measureBlock() {
        // Put the code you want to measure the time of here.
        for i in 1...100000{

            println("ok i need to know the time for execution")


        }
    }
}

并想找出执行 for loop.I 运行 项目的时间,方法是转到产品 -> 执行操作 -> 不构建测试。

我可以看到执行时间为 3.50 秒,但是当我尝试设置基线时单击描边区域,如下图所示:

我收到警告

Would you like to update the baseline values for all tests on all devices? You'll have a chance to review the changes the next time you commit to source control.

现在,当我点击“更新”时,出现如下错误:

如何将我的特定方法的时间基线设置为 Here

这是我的测试项目: https://drive.google.com/file/d/0Bzk4QVQhnqKmUzYyclp6ZnJvekE/view?usp=sharing

你能检查一下 BasicFunctionTest 文件 Target 成员是否包括你的测试目标。您应该能够通过选择文件并导航到文件检查器(目标成员)来检查这一点。