使用TDD在Swift中进行性能testing

Swift学习Test Driven Development 。我在“ProjectNameTests”组中创build了一个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") } } } } 

我想要执行这些方法的性能testing

 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循环的执行时间。我运行该项目转到Product – >执行操作 – > Test Without Building。

我可以看到执行时间为3.50秒,但是当我尝试设置基线点击笔划区域如下图:

在这里输入图像说明

我得到了警告

你想更新所有设备上所有testing的基准值吗? 下次您提交源代码pipe理时,您将有机会查看这些更改。

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

在这里输入图像说明

我如何设置我的具体方法的时间基线为这里

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

您可以检查BasicFunctionTest文件目标成员是否包含您的testing目标。 您应该可以通过select文件并导航到File Inspector(目标成员资格)来检查这一点。