Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to Unit Test and When to Integration Test

I am new to testing in general and am working on a Grails application.

I want to write a test that says "when this action is called, the correct view is returned". I don't know how to go about deciding if I should make something like this a unit test or an integration test. Either test would show me what I want - how do I decide?

like image 502
skaz Avatar asked Jan 19 '23 12:01

skaz


1 Answers

One problem with integration tests is their speed. For me, integration tests take 15+ seconds to start up. In that time, certain things do slip out of mind focus.

I prefer to go with unit tests that start in no more then 2 sec and can be run several times in those 15 seconds. Especially with mockDomain(). Especially with Grails 2.0 implementing criteria and named queries in unit tests.

One more argument for unit tests is they force you to decouple your code. Integration tests always tempt you to just rely on some other component existing and initialized.

like image 143
Victor Sergienko Avatar answered Mar 07 '23 13:03

Victor Sergienko