2009-11-05

JUnit Pocket Guide



Excerpts from JUnit Pocket Guide:

Battery of tests

JUnit:
- Runs tests automatically
- Runs many tests together and summarizes the results
- Provides a convenient place to collect tests
- Provides a convenient place for sharing the code used to create the objects to test
- Compares actual results to expected results and reports differences

Each Test class:
- Has 0..1 setUp() (@Before in JUnit 4)
- Has 0..1 tearDown() (@After in JUnit 4)
- Has 1..N testX()

Write tests first! (test-driven development)

Tests are a practical way to think separately about interface and implementation.

Stubs can avoid the allocation of expensive resources (like remote servers).

Learn APIs with tests.

Document assumptions with tests.

Incorporate tests in your build process for maximum benefits.

--

This book is now a little bit outdated because of JUnit 4, but it still is a great introduction unit tests as a first-class concept in your programming, part of the build process.

Write tests first!

No comments: