Home » Uncategorized

Introducing XP-Style Unit Testing

17 May 2004 598 Views No Comment

I’ve found that it is difficult to push XP style unit testing when you are first introducing unit testing into a team that is not test infected, whether the developers are experienced or not. The best approach I’ve found is to introduce unit testing incrementally.

First introduce the process necessary to acheive continuous integration with unit testing:

• No non-compiling code should ever be checked into the repository

• All unit tests should pass before and after synchronizing with the repository

• All the tests should be run recursively under the src directory to avoid orphaned tests

Then introduce the fundamental best practices of writing unit tests:

• Unit tests should run in isolation (no external dependencies)

• Unit tests should run individually (they don’t depend on state that is setup in other unit tests)

• Unit tests should run fast

• Non unit-tests should be kept separate. All subsystem or acceptance tests should go in a separate source structure and perhaps have a different execution frequency.

Then introduce the extreme aspects of unit testing:

• Unit tests should be written first

• No code should be committed to the repository without unit tests

Related:

JUnit best practices

JavaUnitBestPractices

junit.org

testdriven.com

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.