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

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is OFF
Smilies are ON
Topic review
   

Expand view Topic review: When -[OCMockObject verify] fails, the test runner stops

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

Post by 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!

Top

cron