使用 TDD 在 Swift 中进行性能测试 [英] Performance testing in Swift using TDD

查看:23
本文介绍了使用 TDD 在 Swift 中进行性能测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 class BasicFunctionTest: XCTestCase {变量值:[Int]?覆盖 func setUp() {super.setUp()//把设置代码放在这里.在调用类中的每个测试方法之前调用此方法.}覆盖 func 撕裂(){//将拆卸代码放在这里.在调用类中的每个测试方法之后调用此方法.super.tearDown()}功能测试示例(){//这是一个功能测试用例的例子.XCTAssert(真,通过")}func testPerformanceExample() {//这是一个性能测试用例的例子.self.measureBlock() {//把你想测量时间的代码放在这里.对于我在 1...100000{println("好的,我需要知道执行的时间")}}}}

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

func testPerformanceExample() {//这是一个性能测试用例的例子.self.measureBlock() {//把你想测量时间的代码放在这里.对于我在 1...100000{println("好的,我需要知道执行的时间")}}}

并想找出 for 循环的执行时间.我运行项目,转到产品 -> 执行操作 -> 不构建测试.

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

我收到警告

<块引用>

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

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

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

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

解决方案

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

Just learning Test Driven Development in Swift.I created a class that is subclass of XCTestCase in the "ProjectNameTests" group.

    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")


                }
            }
        }
}

I want to perform performance testing of these method

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")


        }
    }
}

and want to find out the time for execution of the for loop.I run the project on going to Product -> Perform Action - > Test Without Building.

I can see the execution time as 3.50 sec but when i try to set the baseline clicking on the Stroke Area as below image:

I get warning as as

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.

Now when i click on Update the error is as below:

How can i set Baseline of the time for my specific method as Here

Here is my test project : https://drive.google.com/file/d/0Bzk4QVQhnqKmUzYyclp6ZnJvekE/view?usp=sharing

解决方案

Can you check whether BasicFunctionTest file Target membership includes your test target. You should be able to check this by selecting the file and navigating to File Inspector (target membership).

这篇关于使用 TDD 在 Swift 中进行性能测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆