Reputation: 5746
I am writing integration tests with a docket printer and I need it to cut the docket after all the unit tests in a single suite are complete.
Other test frameworks I've used have a tearDownAfterClass
type action, but XCTest doesn't seem to have that?
Is there anyway I can simulate this?
Upvotes: 1
Views: 211
Reputation: 125007
Other test frameworks I've used have a tearDownAfterClass type action, but XCTest doesn't seem to have that?
XCTest
has exactly that feature. There are two versions of tearDown
, one an instance method and one a class method:
- (void)tearDown; // this gets called after each test
+ (void)tearDown; // this gets called after all tests in the suite
Similarly, there are instance and class versions of setUp
, so you can do setup work before each test or once before the suite runs.
Upvotes: 3
Reputation: 5746
There is a crude solution to this. It turns out that XCTest always runs tests in alphabetical order, so like:
/**
* Tests are run in alphabetical order, hence the Z so this runs last.
*/
- (void)testZTearDownAfterClass
{
// ...
}
The same would conversely be true about setUpBeforeClass
:
- (void)test_setUpBeforeClass
{
// ...
}
Upvotes: 0