Search code examples
iosswifttestingtddperformance-testing

Performance testing in Swift using TDD


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:

enter image description here

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:

enter image description here

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


Solution

  • 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).