|
|
Test Case
A Test Case is an instance method on a subclass of
TWTestCase. The subclass itself is
referred to as a fixture. All test cases must begin with 'test', must
take no arguments, and must return void:
@interface MyTests:TWTestCase
-( void ) myTestCase;//valid test case
-( void ) notATest;//doesn't begin with 'test'
-( void ) testFoo:( int ) a;//not a valid test case - takes an argument.
@end
TWTestCase includes a number of assertions
to aid in testing. For details, see the documentation. If any assertion fails, a TWFailure is
thrown.
Example
@implementation MyTests
-( void ) myTestCase
{
MyClass *myClass = [ [ MyClass alloc ] init ];
assertNotNil( myClass );//most assertions have macro equivalents to
//capture the file and line in which the
//assertion takes place
MyOtherClass *result = [ myClass getOtherClass ];
[ self assertTrue:5 == [ result age ] //of course, you don't have to
atFile:__FILE__ //use the macros
andLine:__LINE__
withMessage:[ NSString stringWithFormat:
@"expected age to be 5 but was %i", [ result age ] ] ];
assertFalse( [ result isOld ] );
assertIntsAreEqual( 1, [ result grade ] );
if( ![ self myComplicatedValidation:result ] )
{
fail( @"result was invalid" );
}
}
@end
TestKit divides failed tests into 2 categories: failures and errors. A test that raises a
TWFailure is considered a failure. If any other exception is raised from the test, it is considered an
error.
|
|
|