I have code in method which asserts( ) that a parameter falls within a given range. I’d like to test illegal parameters using a SenTest test case.
My first assumption was that I should use STAssertThrows( … ) however this reports no exception is thrown when the assert fails. Can I catch assert() fails with an STAssert… macro?
[updated to provide an example]
In class Foo.m
@interface Foo : NSObject {
NSUInteger count;
NSUInteger max;
}
@end
@implementation Foo
-(void) bar:(char) c {
assert( count < max );
...
}
@end
In class TestFoo.m
@interface TestFoo : SenTestCase {
Foo testFoo_;
}
@end
@implementation TestFoo
-(void) testBar {
STAssertXXX( YYY );
}
@end
What XXX and YYY can I use to test the failure or otherwise of the assertion in method bar: ?
If you use
NSAssert(orNSAssert1,NSAssert2, etc.) instead ofassert, you can catch anNSInternalInconsistencyException.