When -[OCMockObject verify] fails, the test runner stops

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

When -[OCMockObject verify] fails, the test runner stops

Postby xocobola » 12 Mar 2011, 15:38

Hi
I'm new with OCMock, a good piece of software BTW. I realized that a failure in the verification of a mock halts the execution of the test runner, caused by the exception raised in the [verify] method. It wouldn't be better to just log the error and continue with the other tests? I wrote a category for OCMockObject to add this behavior. Here is it:

OCMockObjectExtension.h
Code: Select all
#import <Foundation/Foundation.h>
#import <OCMock/OCMock.h>

@interface OCMockObject (ErrorReporting)
- (void) verifyAndLog;
@end


OCMockObjectExtension.m
Code: Select all
#import "OCMockObjectExtension.h"


@implementation OCMockObject (ErrorReporting)

- (void) log: (NSString *) message  {
   [(NSFileHandle *)[NSFileHandle fileHandleWithStandardError] writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
      
}

-(void) logError:(NSString *)message {
   message = [NSString stringWithFormat:@"Unknown.m:0:0 Unknown:0: error: %@\n", message];
   [self log:message];
}
   
- (void) verifyAndLog {
   
   @try {
      [self verify];
   }
   @catch (NSException * e) {
      [self logError: [e description]];
   }   
}

@end


The stacktrace is not printed, but it would be really easy to add.

Please let me know if I'm missing a standard way to accomplish this.

Thank you!
xocobola
 
Posts: 1
Joined: 11 Mar 2011, 19:25

Return to OCMock



cron