简体   繁体   English

测试套件在XCTest中运行完毕后执行操作

[英]Performing an action after a test suite has finished running in XCTest

I need to make an API call after all the tests in my test suite has finished running. 测试套件中的所有测试完成运行后,我需要进行API调用。 I'm aware of the method testSuiteDidFinish(_ testSuite: XCTestSuite) , this method does get called after a test suite execution, however it gets called as many times as the number of test cases I have. 我知道方法testSuiteDidFinish(_ testSuite: XCTestSuite) ,在执行测试套件后确实会调用此方法,但是它被调用的次数与我拥有的测试用例的次数相同。 In my test suite I have three test cases. 在我的测试套件中,我有三个测试用例。 I've added an observer to the test class. 我已经在测试课程中添加了一个观察者。 In my observer class, this is what I have: 在我的观察者课上,这是我所拥有的:

public func testSuiteDidFinish(_ testSuite: XCTestSuite) {
   print("done")
}

"Done" gets printed three times after the execution of three tests. 执行三个测试后,“完成”将打印三遍。 Why is doing so? 为什么这样做呢?

The function below works fine for what I was trying to achieve: 下面的功能可以很好地实现我的目标:

override class func tearDown() { 
   }

Whatever is written within it gets called only once, after my tests when a test class finishes executing. 测试类完成执行后,在测试之后,其中写入的所有内容仅被调用一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM