Question

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?

Was it helpful?

Solution

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top