简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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