In one my test files, I have a test function that does the following:
First test from testClassA.m
- (void)testStuffForClassABC
{
id classFOO = OCMClassMock([FOO class]);
OCMStub([classFOO alloc]).andReturn(classFOO);
id classBAR = OCMClassMock([BAR class]);
OCMStub([classBAR alloc]).andReturn(classBAR);
//Do stuff
classBAR = nil;
classFOO = nil;
}
For some reason, the above will interfere with another test file. So if I run the tests independently from another, they will pass.
The affected test from another file.
Second test from testClassB.m
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
self.barObject = [[BAR alloc] init];
self.fooObject = [[FOO alloc] initWithTox:self.barObject error:nil]; //This is now nil
//Can't even step in with the debugger. It skips over.
}
- (void)testInit
{
XCTAssertNotNil(self.fooObject); //Now fails since it's nil.
}
I also tried calling stopMocking after the end of each test but that messes up the first test. I have a feeling that OCMock is not fully cleaning up the objects.
I also noticed there are limitations stated here however that is only for mocking the same class twice.
Aucun commentaire:
Enregistrer un commentaire