Search code examples
objective-cmacoscocoaunit-testingsentestingkit

Any way to run code in SenTest only on a success?


In my Mac Cocoa unit tests, I would like to output some files as part of the testing process, and delete them when the test is done, but only when there are no failures. How can this be done (and/or what's the cleanest way to do so)?


Solution

  • Your question made me curious so I looked into it!

    I guess I would override the failWithException: method in the class SenTestCase (the class your tests run in inherits from this), and set a "keep output files" flag or something before calling the super's method.

    Here's what SenTestCase.h says about that method:

    /*"Failing a test, used by all macros"*/
    - (void) failWithException:(NSException *) anException;
    

    So, provided you only use the SenTest macros to test and/or fail (and chances are this is true in your case), that should cover any test failure.