Reputation: 6250
What is the best way to unit test code that's behaviour changes based on an ifdef?
e.g.
+ (NSString*) someMethod:(NSString*)value {
//Do some stuff ...
#ifdef DEBUG
//Tell user about error
#else
//Suppress error
#endif
}
Upvotes: 3
Views: 1376
Reputation: 46598
you should only need to test release build because this what the user see.
to actually answer your question: you can split the method to 3 method
+ (NSString*) someMethod:(NSString*)value {
#ifdef DEBUG
return [self someMethod_debug:value];
#else
return [self someMethod_release:value];
#endif
}
+ (void)someMethod_debug:(NSString *)value {
//Do some stuff ...
//Tell user about error
}
+ (void)someMethod_release:(NSString *)value {
//Do some stuff ...
//Suppress error
}
then you can test someMethod_debug
and someMethod_release
individually
Upvotes: 1