Unit Tests vs. Integration Tests

Ayende has written a short and to the point post about Unit tests vs. Integration tests.

An even shorter summery of the post is: Unit tests runs faster but integration tests are easier to write.

I believe there is even a greater difference between the two: most of the time integration tests require to set the environment (database, web server etc.) to run properly and can fail because some other component that the test relies didn’t behave as expected.image

Unit tests are harder to write but you get a focused test for your efforts. If that test fail you know exactly what went wrong.

There is however another solution instead of declaring unit testing as hard to write – use an isolation framework which make writing unit test much easier.

I’m not against writing integration tests – I think each project should have both – unit test to test the components and integration tests to test the interaction between them.

Looking to learn more about unit testing and how to write them? Watch our on-demand webinar: “Intro to Unit Testing.

One comment

  1. Janis Tapani November 8, 2011 at 12:17 am

    I completely agree. Not only are unit tests faster to run and harder to write: they must be designed to be independent from environment, as you write and as explained here
    http://arialdomartini.wordpress.com/2011/10/21/unit-tests-lie-thats-why-i-love-them/ on the same topic

Leave a reply

Required fields are marked (*)