Per the comment within the default template for XCTestCase regarding setUp :
Put setup code here; it will be run once, before the first test case.
However, in XCTestCase.h, the comment above setUp states differently:
Setup method called before the invocation of each test method in the class.
To confirm the actual behavior, I put an NSLog withinsetUp to count how many times it was called:
static int count = 0;
- (void)setUp
{
[super setUp];
count++;
NSLog(@"Call Count = %d", count);
}
This resulted in the setUp method being called before every test method (confirming the comment on XCTestCase.h).
I wanted to use the setUp method to create test/mock objects once (e.g. to setup a Core Data test stack). Creating these over and over again would be processor intensive and potentially very slow.
So,
1) What is setUp actually intended to be used for? Surely developers aren't creating objects in it over and over?
2) How can I create these objects only once within an XCTestCase?