Wednesday, September 16, 2009

Integration test hell

For those of you spending lots of time fixing up integration tests, J.B. Rainsberger explains why he thinks integration tests are a scam:

I think the point he is driving home is that we should be focusing more on comprehensive unit tests rather than comprehensive integration tests. I've started changing how I write my integration tests: They should only be verifying the interactivity of components, rather the expected results of the component.

Let's say that a User Service class (UserService) that calls a User Data Access Object class (UserDAO). The unit tests for UserService should use a mock of UserDao and asserting exact equality with the data and exceptions returned from UserDao properly (-- nothing new here). Your integration tests for UserService should use a real UserDao that is connected database (-- again, nothing new here). However, these types of test should NOT be asserting data and exceptions equality. Rather, these integration tests should just be verifying that some data/exceptions are returned. Integration tests should be testing the seams between the UserService and UserDao components, rather than asserting the equality of the value themselves.

Overally, I recommend watching this talk if you have done lots of unit and integration tests writing and wondering if you are duplicating effort.

No comments:

Post a Comment