Is it possible to setup a unit test class to call setup and teardown methods only once for all the test cases not for each test case?
Code in a teardown() block is run upon completion of a test file, even if it exits with an error.
As outlined in Recipe 4.6, JUnit calls setUp( ) before each test, and tearDown( ) after each test. In some cases you might want to call a special setup method once before a series of tests, and then call a teardown method once after all tests are complete.
Prepare and Tear Down State for a Test Class XCTest runs setUp() once before the test class begins. If you need to clean up temporary files or capture any data that you want to analyze after the test class is complete, use the tearDown() class method on XCTestCase .
Actually I found the answer. In order to do class level setup, one needs to implement +(void) setUp
and +(void) tearDown
. This class methods will be called before any test methods run and after all of the test methods run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With