Best approch to testing generic classes...

View: New views
2 Messages — Rating Filter:   Alert me  

Best approch to testing generic classes...

by mr.johnson2070 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello everyone. :-) Junit Starter here..

I supposed to write the unittests for a bigger project. My colleague has written a generic list class. What would be the most effective way to test to the class with all its different implementations?

Thanks!
Patrick


Re: Best approch to testing generic classes...

by Daniel Brolund-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Patrick,

If it is truly generic you only need to test its logic with one type since
the compiler will verify that it can be used for all types. By truly generic
I mean that you e.g. don't have any reflective calls and you don't make any
type casts.

The best way to do it is to write the tests before you write the code,
TDD-style, because by first failing and then passing a test gives you a
verification that the test actually test the stuff you just implemented. If
you want to learn TDD, you could put the list class aside and implement a
new one using TDD and then reflect over the differences (if any).

Cheers
Daniel

On Tue, Oct 13, 2009 at 10:20 AM, mr.johnson2070
<mr.johnson2070@...>wrote:

>
>
> Hello everyone. :-) Junit Starter here..
>
> I supposed to write the unittests for a bigger project. My colleague has
> written a generic list class. What would be the most effective way to test
> to the class with all its different implementations?
>
> Thanks!
> Patrick
>
>  
>



--
---------------------------------------------------------
Daniel Brolund
Agical AB - www.agical.com

work: daniel.brolund@...
phone: +46708754002
blog:http://danielbrolund.wordpress.com
twitter: @danielbrolund
private: daniel.brolund@...


[Non-text portions of this message have been removed]