Re: unit test subclassing
Re: unit test subclassing
- Subject: Re: unit test subclassing
- From: Chris Hanson <email@hidden>
- Date: Wed, 26 Apr 2006 21:58:20 -0700
On Apr 26, 2006, at 9:45 PM, Prachi Gauriar wrote:
On Apr 27, 2006, at 12:15 AM, Olivier Destrebecq wrote:
How can i go about modifying SenTest so that it will allow me to
run that same suite of test several times, each time using
different parameters.
This is admittedly a guess, but it doesn't seem like there's any
reason you can't just created an abstract SenTestCase subclass that
contains the majority of test code and then create subclasses with
special -setUp and -tearDown methods to set up the appropriate
type of object for the given test.
Exactly. Just create an abstract subclass of SenTestCase which
contains your tests, and create subclasses of that which, in their -
setUp and -tearDown methods, set up the expected state for the tests
for your subclasses.
Since you'd use an abstract test case class, you may need to
manually run your tests using SenTestSuite so that SenTestingKit
doesn't detect the presence of the abstract class and try to
automatically run all of its -test* methods.
You don't need to go that far. You can just override -testCaseCount
and -performTest: in the abstract subclass to only invoke super's
methods for *its* subclasses:
@implementation MyAbstractTestCase
- (unsigned int)testCaseCount {
unsigned int count = 0;
if ([[self class] isKindOfClass:[MyAbstractTestCase class]] ==
NO) {
count = [super testCaseCount];
}
return count;
}
- (void)performTest:(SenTestRun *)testRun {
if ([[self class] isKindOfClass:[MyAbstractTestCase class]] ==
NO) {
[super performTest:testRun];
}
}
// put your tests here
@end
With above, the actual run of the tests will be skipped for the class
MyAbstractTestCase and it will be counted as having 0 tests. Its
subclasses will inherit its tests, and they will be run and counted
against instances of its subclasses properly.
-- Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden