Introduction
We use test driven development at Big Switch. Have a look at this short essay by Rob Adams on test driven development to warm up: Rob-Adams-Test-Driven-Development.pdf
For unit testing our Java code we use Junit tests and EasyMock. You can now check the unit test coverage, just use
# make check runs the unit tests with coverage instrumentation ant coverage open floodlight/target/coverage/index.html
Whenever you change or add some code please also add unit tests for your changes and consider extending the coverage of the class you are touching even if you didn't change it. We want to increase our coverage!!
Documentation
Documentation for EasyMock in particular is unfortunately somewhat sparse but I will try to collect pointers to useful tutorial and documentation here. Please update and comment if you find a particular article useful / useless / confusing.
Junit Tutorial (1)
Junit Tutorial (2)
Unit testing with JUnit and EasyMock
Mock controls with EasyMock
Using captures with EasyMock
EasyMock README
Known caveats and oddities:
- assertTrue has two signatures, one with a string message and one without. If you use the one without and the assert fails, you will get "Assertion Failed: null". The null just means that the string message is null it doesn't mean that there was a NPE in your expression! Yes, that's a very stupid behavior! So please either use a message whenever you use assertTrue, or use assertEquals(true, expression)