Re: Unit testing framework suggestions?
Re: Unit testing framework suggestions?
- Subject: Re: Unit testing framework suggestions?
- From: Tim Hart <email@hidden>
- Date: Thu, 23 Sep 2004 16:00:42 -0600
On Thursday, September 23, 2004, at 02:54PM, M. Uli Kusterer <email@hidden> wrote:
>At 20:56 Uhr -0500 22.09.2004, Tim Hart wrote:
>>See also
>>
>>http://testkit.sourceforge.net
>
>BTW -- does anybody know some good tutorials about Unit testing? I
>don't mean about how to use the frameworks, but rather on how to do
>it for the most benefit, and why it's better than other methods, and
>how this relates to Cocoa and Objective C.
A good resource for unit testing in general:
http://c2.com/cgi/wiki?UnitTestTutorial
Why is it better than other methods? I'm a unit testing fan, but 'better' is a very subjective question.
The biggest benefit I gain by keeping a suite of unit tests is this:
I have a suite that I can run on-demand, that takes a fraction of the time it would take to manually test everything, and is a reasonable measure of the overall health of the system. A breaking test is a guarantee that there is either something wrong with the code - or the test. A unit test written to 'uncover' a bug guarantees that the same bug will not reappear (although the same symptoms due to *another* bug might). Unit tests aren't really useful unless they are run on a regular, frequent basis.
Note that a passing suite of unit tests does *not* guarantee flawless code. FIT tests and user acceptance testing is still A Very Good Idea(tm). Unit tests do aid debugging by giving you a direct and immediate entry point into the method/function that isn't behaving appropriately.
There are several styles to unit testing. Martin Fowler compares 2 types of unit testing here
http://www.martinfowler.com/articles/mocksArentStubs.html
TestKit has a beginning API for mock objects, but the API is currently absent code to count/verify how many times a method is called. That will follow soon.
How does this relate to Cocoa/Objective-C? I've not seen an article relating to this. Can you be more specific with your questions?
>E.g. UnitKit keeps separate "test objects", which I find kinda odd.
>I'm wondering why one shouldn't put the tests in the object in need
>of the testing instead... things like that.
One of the main purposes of a unit testing suite is to enable the developer to concentrate on the tests, and not on the setup/identification and execution of those tests. A very convenient way to do this in Objective-C is to look for all subclasses of a particular class. In the case of TestKit, it's TWTestCase. That requirement does limit the developer from making tests part of the class being tested.
I don't know that I would want to couple my tests to the class in question so tightly, though. As a separate library, I have the choice of delivering my test suite along with the code itself to the client, or not. The client has a choice of installing the test suite on the same machine - or not. It's a bit more flexible.
NUnit, which is a unit testing kit for C# (http://www.nunit.org), would actually allow you to bind your test cases to the class being tested if your chose. The reason this is possible is due to C#'s attributes - class metadata. NUnit test cases do not have to inherit from any particular class.
>--
>Cheers,
>M. Uli Kusterer
>------------------------------------------------------------
> "The Witnesses of TeachText are everywhere..."
> http://www.zathras.de
>
>
_______________________________________________
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