Wednesday, October 6, 2010

When is a unit test not a unit test?

There's a great deal written on this topic already, but obviously not enough. I had a very interesting chat with a colleague the other day about what constitutes a unit test vs integration, system etc.

I think the boundaries are mirky, but for me at least, a unit test is something that can be constructed with little friction and it can execute fast. I don't really care much about whether I'm testing things that are technically outside of the "unit" I'm working on e.g. if there's an in-memory database available and I can easily construct a test of my code, I don't think I'm crossing the boundary into integration testing. In fact what I've found is that it is sometimes easier to set up an  in memory database for the purposes of testing rather than mocking it.

Now of course when you start crossing process boundaries you are moving into the world of integration tests. This falls into the category of "being slow to run" though.

At the end of the day I'm not too worried about whether my test is a unit test so long as its easy to write and quick to execute. If it isn't then I'm happy to have it fall into another category of testing.

No comments: