2

I'm writing this unit test:

   - (void)testCellValues
{
    id bookMock = [OCMockObject mockForClass:[LBBook class]];
    [[[bookMock stub] andReturn:@"Book Title"] title];
}

Of course there is some code after that. But at this point I'm having this error when I execute the test:

[LBReviewsDashboardDataSourceTest testCellValues] failed: OCMockObject[LBBook]: cannot stub or expect method 'title' because no such method exists in the mocked class.

But LBBook class has the attribute title. This is the LBBook Class:

@interface LBBook : LBManagedObjectFactory

@property (nonatomic, retain) NSString * title;

@end

I cannot realise what is happening here, why Does OCMock return that error if the class has title attribute?

Thanks in advance.

Gabriel Goncalves
  • 5,132
  • 3
  • 25
  • 34

1 Answers1

5

CoreData uses dynamic properties. These are not yet properly supported in OCMock. It is possible to stub valueForKey: instead. See also: OCMock: stub a @dynamic property and OCMock with Core Data dynamic properties problem

Community
  • 1
  • 1
Erik Doernenburg
  • 2,933
  • 18
  • 21