Welcome to

Luis Gonçalves website

Rules to design good Unit Tests

Hi guys, this post will be short but in my opinion it is really useful for agile developers. Some weeks ago, when I was reading the book “Agile Coaching” by Rachel Davies and Liz Sedley, I found an interesting part that I wanted to share: “Unit tests Rules” by Michael Feathers.

Michael Feathers tells us that a test is not the unit test if:

  • it talks to the database
  • it communicates across the network
  • it touches the file system
  • it can´t run correctly at the same time as any of your other unit test
  • you have to do special things to your environment (such as editing config files) to run it

He also tells us that tests which do these kind of things are not bad tests. Most of times, it is necessary to have these kind of tests, however, it´s important to separate them from true Unit Test so that we can keep a set of tests that we can run fast whenever we make changes.

This is a short pillar I wanted to share with you.

Final3dPostCTA

4 thoughts on “Rules to design good Unit Tests”

  1. Patrick Lamasney says:

    Great post, Luis. Say, aren’t the tests in the list above basically integration tests - and that that is the differentiation that Mr. Feathers was making?

    1. Luis Goncalves says:

      Thanks ;) I believe so… Those tests are still necessary but maybe in a different set…

      1. Alex says:

        Thats right. When we say unit we mean the smallest possible amount of code which can be testested. In most of the cases is a funciton. So if you perform some system call in your test you are going to test your system and system is not a part of your function therefor this is not an unit-test.

  2. Luis Goncalves says:

    Thanks Alex :)

Leave a Reply

Your email address will not be published.

*

Facebook

Get the Facebook Likebox Slider Pro for WordPress