A new approach to unit tests

There is an article on  the Legolas in Minas Tirith blog which is about Unit Testing. The posting state that Unit Testing (in the form of JUnit or TestNG) is kind of flawed because it tests implementations of an interface.
So if you create a new implementation of the interface, you have to create a new test.

So the suggestion is to talk something from Design By Contract and connect it with Unit Testing. So Unit Testing is concerned with testing the Contract definied by an interface. So every implementation has to fullfill the contract of the interface.

With TestedBy, tests declared on an interface (or a superclass) can be run upon all implementers to verify they’re respecting the behaviour and contract defined in the super type. IOW the API designer not only provides the interfaces, but also a set of test classes verifying expected behaviour. Then every implementer would supply its own implementation and run the tests provided by the API designer against its concrete classes to verify they are respecting not only type safety but also beahviour/contract safety for which the API was designed. TesteBy here invokes a test defined for an interface passing to test class a concrete instance of class implementing the interface under test.

More on this topic can be read in A new approach to unit tests.


Tags: , , , , , ,

One Response to “A new approach to unit tests”

  1. guenthernoack Says:

    Maybe this is of interest for you: http://c2.com/cgi/wiki?AbstractTestCases or http://gnoack.wordpress.com/2008/09/02/junit-testing-abstract-classes-and-interfaces/

    This is also the way that’s suggested in the JUnit (or xUnit?) FAQ. I don’t see why this means xUnit is a bad technology to do these kinds of tests.

    Best regards,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: