ER: Make creating custom OCUnit assertions easier

Originator:ddribin
Number:rdar://7333580 Date Originated:24-Oct-2009 10:11 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 3.2
Classification:Enhancement Reproducible:N/A
 
24-Oct-2009 10:11 AM Dave Dribin:
Custom assertions are in important design pattern to help keep test code clean and reusable:

  <http://xunitpatterns.com/Custom%20Assertion.html>

Unfortunately, assertions in OCUnit are huge, 20- to 30-line macros, and it's not easy to create custom assertions.  This process should be made easier.

It's possible to use a method for a custom assert, like:

- (void)customAssertStringsEqual:(NSString *)s1 expected:(NSString *)s2
{
    STAssertEqualObjects(s1, s2, nil);
}

But then all assertion failures show up on the line inside the custom assertion, not the caller of the custom assertion.  This is not useful when the test fails and you want to jump the failing test method, not inside the assertion.

The only way to have a custom assertion display the proper line on failure is to make them a macro using the __LINE__ macro.  Thus, you have to create a large multi-line macro just to add a simple custom assertion.

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!