Unit Test can't find Core Data model file

前端 未结 5 1344
無奈伤痛
無奈伤痛 2020-12-10 02:21

I\'ve created a project with a Core Data model in it. The application looks for the model file (.momd) and runs just fine.

Unfortunately, the unit test keeps returni

5条回答
  •  Happy的楠姐
    2020-12-10 03:00

    Had a similar problem, i solved it using the OCMock framework, so i did not need to change the application code

    @interface TestCase()
        @property (nonatomic, strong) id bundleMock;
    @end
    
    @implementation TestCase
    
    - (void)setUp
    {
        self.bundleMock = [OCMockObject mockForClass:[NSBundle class]];
        [[[self.bundleMock stub] andReturn:[NSBundle bundleForClass:[self class]]] mainBundle];
        [super setUp];
    }
    
    - (void)tearDown
    {
        [self.bundleMock stopMocking];
        [super tearDown];
    }
    

提交回复
热议问题