문제

Lets say that my SUT (system under test) needs to supply the @"CFBundleIdentifier" from infoDictionary in a property bundleIdentifier.

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

The problem is that [[NSBundle mainBundle] infoDictionary] returns an empty NSDictionary in test environment, which means I am testing nil equal nil here. Also, this test smells

How would you test it?

도움이 되었습니까?

해결책

The Solution I used for now is to inject the inforDictionary to my sut in the constructor

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

   XCTAssertEqualObjects(sut.bundleIdentifier, BUNDLE_IDENTIFIER);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top