XCTAssertThrows: Raising an exception in a dispatch_once() block makes the test to never execute assertion
| Originator: | g.tranchedone | ||
| Number: | rdar://14493555 | Date Originated: | 19-Jul-2013 04:53 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode Version 5.0 (5A11344j) |
| Classification: | UI/Usability | Reproducible: | Always |
Summary:
If you have a method like this:
+ (void)foo
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[NSException raise:@"MyException" format:@"Something went wrong"];
});
}
and a unit test like this:
- (void)testRaiseException
{
XCTAssertThrows([MyClass foo], @"Test Failed");
}
the test will never pass because the execution is interrupted before the assertion is evaluated.
Steps to Reproduce:
Create a project with the sample code above and run the Test configuration.
Expected Results:
The test should succeed and the 'unit test status mark' should show the green checkmark.
Actual Results:
The execution of the test is interrupted when the exception is encountered. Tests are said to be succeeded but that's simply because the assertion was never executed.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!