It is usually more complicated to write unit tests due to having to deal with mock objects than integration tests in a large Grails project. This article even suggests we can even do away with unit tests altogether and write only integration tests which I tend to agree.
The only disadvantage I see is the speed of execution for integration test as compared to same unit test.
What are your thoughts about this from your actual experience working on a large scale Grails project?
If we write a unit test that tests exactly same method and also write integration test that also tests exactly same method, is this normal way of writing tests?
What you ended up with in terms of ratio of unit tests to integrations tests in actual large Grails project?
Have you successfully completed a large Grails project without writing any tests?
I always write my tests as unit tests if possible. I do this because:
An example of where I would write an integration test is if I want to test a Spring bean that I’ve defined in
resources.groovy. Although I could instantiate the class and test it directly, my test would then need to know the current implementation class of that bean (which might change).In the long-run I think it’s actually more complicated to write integration tests, because the cost of maintaining them over time is higher than unit tests. Groovy/Grails has excellent support for mocking/stubbing, so the cost of mocking dependencies in unit tests is relatively low. Here’s a real-world example from one of my unit tests where I:
messageSourceSpring bean that would normally only be available in an integration testvalidate()method, inspect the.errorsproperty, etc.