Good Unit Test CheckList

Writing unit test? but don’t know if you covered everything? Here is a simply good unit test checklist.

Good Unit Test Checklist are green light for refactoring

Here are a few items I try to respect every time I write unit tests. It’s a solid and good unit test checklist. At least good for most of my code 🙂

Edit: a more extended and detailed list I wrote for DZone.

  • My test class is testing one and only one class
  • My methods are testing one and only one method at a time
  • My variables and methods names are explicit
  • My test cases are easy to read by human
  • My tests are also testing expected exception with @Test(expected=MyException.class)
  • My tests don’t need access to database
  • My tests don’t need access to network resources
  • My tests respect the usual clean code standards (length of lines, cyclomatic complexity,…)
  • My tests control side effects, limit values (max, min) and null variables (even if it throws an exception)
  • My tests can be run any time on any place without needing configuration
  • My tests are concrete (ex. dates are hardwired, not computed every time, strings too…)
  • My tests use mock to simulate/stub complex class structure or methods

Maybe you’ve already done a great deal  by appointing a Test Supervisor that checks every aspect of the finished product. That’s terrific. Congratulations.

But there are still bugs ?  Your team is telling you that this little change you asked took the all system down ? How comes ?

For more details about unit tests, see my series:  Test Culture Episode 1. The 101 Unit Testing Guide For Busy Managers.

I’m pretty sure there are more point to this unit test checklist.  Any idea ?

Author: Jean-Baptiste Rieu

Trained software engineer and now product manager. Living in South-Korea, working on post-purchase experience @Coupang, the first e-commerce company here. Blogging mostly to practice writing, and to engage with others on life in Korea, products, engineering, books and anything worth geeking about.