Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integration vs Unit Testing

Im developing with Grails. Since the framework will bootstrap data and a fully flushed out spring context, I find that I write a lot of integration tests for services. Let me rephrase that: I find I write no unit tests for services, only integration tests. Is this a bad idea? The only downside I see to it is that my tests take a bit longer to run.

I do use unit testing on controllers, as in a controller I am testing the various application flows, result types, redirect logic, etc. But the majority of tests I write are integration tests. This seems a break from tradition J2EE tests, where mostly unit tests are written.

edit- to be clear, Im not writing integration tests because the code is so complicated only integration tests will do. Im writing integration tests because it is easier to test everything together, since the framework gives you so much. I do mock certain things, like if a service collaborates with the acegi authenticationService, I mock that. I also mock anytime we interact with a webservice, because you have to in order to get a test that runs without special setup.

like image 923
hvgotcodes Avatar asked Aug 02 '10 22:08

hvgotcodes


2 Answers

I clearly see a trend towards more functional tests and fewer unit tests, in particular for heavily-connected components low on logic. If I implement a complicated algorithm in a particular class, I will usually write unit tests for it, but if the complexity is due to integration with other components (which is very frequently the case), unit tests are not worth the hassle.

like image 106
Gintautas Miliauskas Avatar answered Nov 11 '22 10:11

Gintautas Miliauskas


In general, the important measure is the code coverage.

In can be advantageous to do integration tests if the global interface is more stable (less subject to change).

like image 37
h3xStream Avatar answered Nov 11 '22 08:11

h3xStream