【问题标题】:Performance testing in Swift using TDD使用 TDD 在 Swift 中进行性能测试
【发布时间】:2015-10-10 15:53:33
【问题描述】:

刚刚在Swift 中学习Test Driven Development。我在“ProjectNameTests”组中创建了一个属于XCTestCase 的子类的类。

    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 循环的时间。我在转到产品-> 执行操作-> 测试而不构建时运行项目。

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

我收到警告

您想更新所有测试的基线值吗? 设备?下次您将有机会查看更改 致力于源代码管理。

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

如何将我的具体方法的时间基线设置为Here

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

【问题讨论】:

    标签: ios swift testing tdd performance-testing


    【解决方案1】:

    您能否检查 BasicFunctionTest 文件目标成员资格是否包含您的测试目标。您应该能够通过选择文件并导航到 File Inspector(目标成员资格)来检查这一点。

    【讨论】:

    • 感谢您的回复......我仔细检查了它......它完成了......我已经上传了我的项目......请看我的问题
    • 奇怪,我只是尝试了相同的步骤并且能够更新基线。
    • 你刚刚在我创建的演示项目中试过了吗?你使用的是哪个xcode版本?
    • 是同一个UnitTesting项目,Xcode版本是6.4
    • 我刚刚下载了 xcode 6.4 并进行了测试..一切都很好..我的错误是使用 xcode 6.3,尽管其中有一些错误 :) 谢谢
    猜你喜欢
    • 2014-06-02
    • 2018-02-25
    • 1970-01-01
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    相关资源
    最近更新 更多