2014-03-04 130 views
0

可以说我的SUT(被测系统)需要在属性bundleIdentifier中提供来自infoDictionary@"CFBundleIdentifier"我如何单元测试infoDictionary行为

- (void)testAppPackageName 
{ 
    //fixture code is happening in setUp function 
    XCTAssertEqualObjects(sut.bundleIdentifier, [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]); 
} 

的问题是,[[NSBundle mainBundle] infoDictionary]在测试环境中,这意味着我零等于无这里测试返回一个空NSDictionary。 另外,这个测试有味道

你会如何测试它?

回答

0

我用现在的解决方案是将inforDictionary注入到我的SUT在构造

- (void)testAppPackageName 
{ 
    //fixture 
    NSDictionary* appInfo = @{ @"CFBundleIdentifier" : BUNDLE_IDENTIFIER}; 
    sut = [[SomeClass alloc] initWithInfo:appInfo]; 

    XCTAssertEqualObjects(sut.bundleIdentifier, BUNDLE_IDENTIFIER); 
}