0
OCMocks를 올바르게 사용하고 있는지, 아니면 .lib 파일이 아닌 cocoapods 버전을 사용하고 있는지 여부가 확실하지 않습니다.왜이 OCMock 확인에 실패 했습니까?
@property (nonatomic, strong) MWGoogleTrends *googleTrends;
:
@implementation MWViewController {
NSArray *_trends;
}
@synthesize googleTrends;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_trends = [self.googleTrends getLatestTrends];
}
googleTrends 물론 헤더 속성이다 : 여기
시험은#import "MWViewControllerTests.h"
#import "MWViewController.h"
#import "OCMockObject.h"
#import "MWGoogleTrends.h"
#import "OCMockRecorder.h"
@implementation MWViewControllerTests {
MWViewController *vcSUT;
id googleTrends;
NSArray *trends;
}
- (void)setUp
{
[super setUp];
vcSUT = [[MWViewController alloc] init];
googleTrends = [OCMockObject mockForClass:[MWGoogleTrends class]];
vcSUT.googleTrends = googleTrends;
trends = [[NSArray alloc] initWithObjects:@"trend1", @"trend2", @"trend3", nil];
[[[googleTrends stub] andReturn:trends] getLatestTrends];
}
- (void)tearDown
{
// Tear-down code here.
[super tearDown];
}
- (void)test_ViewDidLoadShouldCallGoogleTrends_getLatestTrends
{
[[googleTrends expect] getLatestTrends];
[vcSUT view]; // calls loadView
[googleTrends verify];
}
여기
@end
은 VC의 야
나는 그것이 그 아래에 다음과 같은 테스트를 통과하기 때문에 호출되는 :
- (void)test_numRowsInTableViewShouldBeNumOfTrendsReturnedFromGetLatestTrends {
[vcSUT view];
int numSections = [vcSUT tableView:nil numberOfRowsInSection:0];
STAssertEquals(numSections, 3, @"should be 3 sections");
}
- (void)test_cellForRowAtIndexPath_should_return_cell_with_trendName_as_text {
[vcSUT view];
UITableViewCell *cell1 = [vcSUT tableView:nil cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
UITableViewCell *cell2 = [vcSUT tableView:nil cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]];
UITableViewCell *cell3 = [vcSUT tableView:nil cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:2]];
STAssertEquals(cell1.textLabel.text, @"trend1", @"cell text should be correct trend name");
STAssertEquals(cell2.textLabel.text, @"trend2", @"cell text should be correct trend name");
STAssertEquals(cell3.textLabel.text, @"trend3", @"cell text should be correct trend name");
}
@end
가 어떤 식 으로든 관련이있는 경우에는 컴파일러에서이 경고를 받고, 확실하지 :
ld: warning: directory not found for option '-L/Users/markw/Projects/XCode/OReillyCasts/MWGoogleTrends/Pods/build/Release-iphoneos'
표시되는 문제는 무엇입니까? –
OCMockObject [MWGoogleTrends] : 예상되는 메서드가 호출되지 않았습니다 : getLatestTrends. ETA : 아래 업데이트 된 테스트가 통과되었음을 보여주기 위해 위에서 업데이트되었으므로 ViewDidLoad가 호출되고 스텁 된 결과가 반환됩니다. –
나는 (실제로 OCMock을 사용 했으므로 오랜 시간이 걸렸습니다) 이전 스텁 메서드가 호출 될 것이라는 기대를 설정하기 위해 메서드를 미리 작성했기 때문에 가능하다고 생각합니다. – InsertWittyName