Archive for January, 2008
Thursday, January 31st, 2008
I'm trying to figure out why Cobertura coverage reports on my Groovy and Grails code don't show the branch coverage that I expect they should. I noticed that at some point in the past, Cobertura did show a correct branch report. So I tried the grails code-coverage plugin ...
Posted in grails, testing | 6 Comments »
Wednesday, January 30th, 2008
I released an updated version of the code coverage plugin for Grails today. This release incorporates some of the suggestions others have offered in the last few days:
renamed the "test-app-coverage" script to "test-app-cobertura" - perhaps in the future we will add another code coverage library (EMMA?) to the plugin ...
Posted in grails, testing | No Comments »
Sunday, January 27th, 2008
When I use Cobertura to instrument my Grails Controllers, it doesn't seem to accurately report on the branch coverage. For instance, the index closure in my controller looks like this:
def index = {
redirect(action:list,params:params)
}
The tests look like this:
void testIndex(){
stateController.index()
assertEquals('/state/list', stateController.response.redirectedUrl)
}
void testIndexWithParams(){
stateController.params.max=10
stateController.index()
assertEquals('/state/list?max=10', stateController.response.redirectedUrl)
}
I don't believe there are actually two possible branches ...
Posted in grails, testing | 5 Comments »
Saturday, January 26th, 2008
After creating a Cobertura Plugin for Grails, I thought I'd give it a test run on some simple domain class logic and tests. Consider this example in grails-app/domain:
class State {
String name
String postalCode
def isMinnesota(){
return 'MN' == postalCode
}
def isWisconsin(){
return 'WI' == postalCode
}
}
The two helper methods (isMinnesota and isWisconsin) deserve some tests:
void ...
Posted in grails, testing | No Comments »
Saturday, January 26th, 2008
I've always liked having code coverage reports to help me find branches of code that aren't being tested. On the past couple of Java projects I've worked on we used Ant and Cobertura to generate those reports. It turns out that compiled Groovy code can also be instrumented ...
Posted in grails, testing | 5 Comments »