Re: Unit testing framework suggestions?
Re: Unit testing framework suggestions?
- Subject: Re: Unit testing framework suggestions?
- From: Marco Scheurer <email@hidden>
- Date: Fri, 24 Sep 2004 14:51:16 +0200
On Sep 24, 2004, at 2:00 PM, M. Uli Kusterer wrote:
At 4:56 Uhr +0200 24.09.2004, Marco Scheurer wrote:
One reason is that tests can have their own state and ivars, and it
wouldn't be a good idea to mix this with the class you want to test.
A-ha! Thanks, that makes a lot of sense. I knew there had to be some
obvious reason.
(...)
All the xUnit packages are more or less derived from the original
Smalltalk "SUnit". The seminal article is by Kent Beck, and can be
found at http://www.armaties.com/testfram.htm . So there is also an
historical reason for doing it in subclasses of Testcase.
However, this can be done differently. For instance, Marcel Weiher
advocates putting the tests in a category of the tested class.
Yes, that was what I thought. It wouldn't be too hard to use e.g. the
preprocessor to remove these tests from the class for the final
production build. Since I know that I prefer things that are related
(like code and the tests that go with it, or code and its
documentation) together in one file, because otherwise it's too easy
to have them go out of sync.
Not really if you run your tests after each change, or frequently (at
least daily). A lot of our users actually prefer to keep the tests
separated from the code, in a different target or a different project.
One reason is to avoid deploying the test code and the testing
framework (although I think that in some cases it can be nice to be
able to run the tests at the customer's site).
But of course, if my test wants to keep state, it'd obviously be a
little bothersome to have that in the same class. It would even
violate encapsulation, come to think of it. Thanks, I think that
aspect is now a little clearer to me.
Just a thought: Does any of the kits have some macros for "default
tests"? E.g. some way to just say: Arguments to this function (or its
result, or whatever) range from X to Y, and then it would generate
code to try the edges of that range (both inside and out)
automatically?
The answer is certainly not like this, AFAIK none of the kits
automatically generate code. To do this kind of tests with OCUnit you
would use one of a bunch of macros to test that exceptions are thrown
or not, for instance:
- (void) testSetRatioRange
{
STAssertNoThrow ([x setRatio: minimum], nil);
STAssertNoThrow ([x setRatio: maximum], nil);
STAssertThrowsSpecificNamed ([x setRatio:minimum - epsilon],
NSException, NSInvalidArgumentException, nil);
STAssertThrowsSpecificNamed ([x setRatio:maximum + epsilon],
NSException, NSInvalidArgumentException, nil);
}
I'm not sure that automatically generating such code is worth the
effort.
Marco Scheurer
Sen:te, Lausanne, Switzerland http://www.sente.ch
_______________________________________________
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