Michael Feathers has posted a set of Unit Tests Rules http://www.artima.com/weblogs/viewpost.jsp?thread=126923
A test is not a unit test if:
I understand his motivations to write this, however I think his position is very aggressive. Frankly, I have learned UnitTests reading tests from other people, and I’ve always seen some kind of dependencies with the Filesystem and sometimes a Database, and I don’t think this makes these tests less Unit.
I would like to reconsider each of first three points:
It talks to the database.
- use different db for unit and integration testing
- the database can be created from scratch easily
- tests uses the smallest amount of data they could
- unit tests always execute though a local db instance
It communicates across the network
I always avoid to depend in another machine, so if you need to use the network always use localhost, and like the db, you must be able to setup the server side easily in your dev/build box.
It touches the file system
I completely disagree this one, it’s like if you said “it touches the memory”. I don’t like to depend on predefined paths and I always try to put my testfiles as resources of my test library, however there are too many situations where using the FS make things easier.
Finally I agree with the last two sentences…