I followed this great article to get into Unit Testing regarding Core Data. The setup seems simple and involves just some view lines of code.
- (void)setUp;
{
[MagicalRecord setDefaultModelWithClass:[self class]];
[MagicalRecord setupCoreDataStackWithInMemoryStore];
}
- (void)tearDown;
{
[MagicalRecord cleanUp];
}
- (void)testSomeCalculationOnMyEntity;
{
NSNumber *count = [MyEntity MR_numberOfEntities];
// STAssert([testEntity customCalculation] == expectedValue, @"expected a good calculation");
}
@end
The problem is, that each time I for example check for the amount of entities in the in memory set up of Core Data by calling [MyEntity MR_numberOfEntities] (like above), I get the amount of objects, which are stored in the file based setup which are a couple of thousand objects. How does this happen? I mean the second line in setUp indicates the in memory one, doesn't it? And this case should return 0 as the amount of objects stored.
Thanks for any suggestions!
Edit:
@casademora put me on the right track. The following works setup works fine for me now.
- (void)setUp;
{
[MagicalRecord cleanUp]; // This solved the mystery.
// I don't now why I had to remove this line, though.
// [MagicalRecord setDefaultModelWithClass:[self class]];
[MagicalRecord setupCoreDataStackWithInMemoryStore];
}
- (void)tearDown;
{
[MagicalRecord cleanUp];
}
- (void)testSomeCalculationOnMyEntity;
{
NSNumber *count = [MyEntity MR_numberOfEntities];
// STAssert([testEntity customCalculation] == expectedValue, @"expected a good calculation");
}
@end