Ayende @ Rahien

It's a girl

Unit tests vs. Integration tests

I can sum it up pretty easily:

Unit tests:
65 passed, 0 failed, 5 skipped, took 7.49 seconds.

Integration tests:
45 passed, 0 failed, 0 skipped, took 284.43 seconds.

Except, there is one thing that you aren’t seeing here. Writing an integration tests is about as straightforward as they come. Execute the user scenario, assert the result. There is no real knowledge required to write the test, and they are very easy to read and understand.

Unit tests, however, often require you to understand how the software work in much finer detail, and they often make no sense to someone who isn’t familiar with the software.

Comments

John Chapman
05/10/2009 01:37 PM by
John Chapman

Am I the only one that finds it shocking that 65 unit tests took 7.49 seconds to run? Based on that timing it sounds like the unit tests may be doing more than expected. I'm used to 65 unit tests taking a fraction of a second.

What kind of work are your unit tests doing? It almost seems like they would need some level of "integration" to make them that slow.

Igor Tamaschuk
05/10/2009 01:48 PM by
Igor Tamaschuk

And you are right. Moreover, every newbie in the test driven approach going to write the integration tests in first order. Especially if he is not strong enough in OOD and his design is like a one big transaction script with GOTOs :)

Ayende Rahien
05/10/2009 01:48 PM by
Ayende Rahien

John,

That number also include the time to spin up the test framework, but yes, they are oing a lot

Paulo Aboim Pinto
05/11/2009 01:18 AM by
Paulo Aboim Pinto

I have this two levels of tests too. Usually the unit test mock the next layer (example testing Business Layer and mock the Data Access Layer).

In the integration test I will run some database scripts to create the database initial state and run the integration tests that will do on Business layer and I will not mock the DAL. The test will go to the end of the chain .. to the database.

this is the way that I do.. and that's why the integration tests take more time then the unit tests (in my case).

Regards

Paulo Aboim Pinto

Odivelas - Portugal

Comments have been closed on this topic.