I have a test case and a helper class. In the helper class I want to use asserts too like here:
MainTests.h
#import <SenTestingKit/SenTestingKit.h>
@interface MainTests : SenTestCase
@end
MainTests.m
#import "MainTests.h"
#import "HelperClass.h"
@implementation MainTests
- (void)testExample {
HelperClass *helperClass = [[HelperClass alloc] init];
[helperClass fail];
}
@end
HelperClass.h
#import <SenTestingKit/SenTestingKit.h>
@interface HelperClass : SenTestCase
- (void)fail;
@end
HelperClass.m
#import "HelperClass.h"
@implementation HelperClass
- (void)fail {
STFail(@"This should fail");
}
@end
Sidenote: I had to make the helper class a subclass from SenTestCase to being able to access the assertion macros.
The assertion from the helper class is ignored. Any ideas why? How can I use assertions in helper classes?
I had this same problem today and came up with a hack that worked for my purposes. Poking into the
SenTestCasemacros, I noticed that they call [self …] on the helper but didn’t trigger the asserts. So, wiring up the source class to the helper got it working for me. Changes to your question classes would look like:MainTests.h
MainTests.m
HelperClass.h
HelperClass.m
It is entirely possible that additional overrides are needed for more advanced functionality, but this did the trick for me.