Unit Test Checklist
One of the things that always is an issue for people who are new to unit testing is what kind of tests should be written in order to fully exercise a method. So here is a handy checklist that you can use as a guide while writing tests.
Baseline Tests
Write a few test that use the code in the manner it should be used ie in a way that you expect to work and returns the kind of data you are expecting.
Error Tests
The opposite of Baseline tests are test that expect a particular error to be thrown based on incorrect input. Write a test that expects the different kinds of errors that can be thrown by your method.
Null Tests
Do you know what happens to the logic in your method if you pass in some or all parameters as null? Now is the time to find out by writing tests to this end, and making sure your method responds in the way you expect.
Boundary Tests
Write test to test the upper and lower limits of parameters that can be passed in. Test passing in numbers as negatives, or dates outside of the ranges you expect.
Parameter Variation Tests
Make sure you have a few tests that provide parameter variations to give the internal workings of your method a good stretch and to try and find any areas and conditions under which your method fails to return an expected result.
There’s no doubting the power that a good set of unit tests gives you, but I understand that getting started with testing is sometimes difficult for developers not used to test-first coding. My best advice is to stick with it – it just takes a little while to click, but once it does, the benefits are worth waiting for.
