Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect code coverage results on XCode when testing exceptions

I'm creating a static library for iOS and am trying to get code coverage data for it's unit tests. I'm using CoverStory to visualise the generated code coverage files.

I get correct information for most of the tests.

However, any test which is verifying that an exception should be thrown is not being marked as tested.

For example the method

- (void)shouldThrow:(BOOL)throw {

    if (throw)
       @throw [NSException exception...];

    NSLog(@"not thrown");

}

Tested with the test

- (void)testShouldThrow {
    STAssertThrows( [myObject shouldThrow:YES], @"Should have thrown an exception");

    STAssertNoThrow( [myObject shouldThrow:NO], @"Should not have thrown an exception");
}

Passes all the tests (i.e. the exception is being thrown correctly). However, the code coverage doesn't show 100% - the line with @throw on is not being marked as tested.

Any ideas?

like image 912
deanWombourne Avatar asked Mar 15 '12 12:03

deanWombourne


1 Answers

The line with @throw on it does not complete (because the exception is thrown), so it doesn't get marked as covered. You could file a bug, but this is likely pretty hard for them to fix. If it's a single line in a branch statement, it may be very hard to tell if it was tested, but if there are lines before it that were executed, you'll just have to assume that it was as well.

The bad thing is you'll never be able to get to 100%.

like image 97
wbyoung Avatar answered Oct 21 '22 01:10

wbyoung