我按照这篇很棒的文章进入了有关核心数据的单元测试。设置看起来很简单,只涉及一些视图代码行。
- (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
问题是,每次我通过调用(如上)检查核心数据的内存设置中的实体数量时,我都会得到对象的数量,这些对象存储在基于文件的设置中,它们是几千个对象。这是怎么发生的?我的意思是第二行表示内存中的行,不是吗?这种情况下应该返回 0 作为存储的对象数量。[MyEntity MR_numberOfEntities]
setUp
感谢您的任何建议!
编辑:
@casademora 让我走上了正轨。以下工作设置现在对我来说很好。
- (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