What could cause something like this:
The line def result
shows only 2/6 branches covered, even though it has NO BRANCHES, while the following line, which actually has a conditional, is ok.
What's going on? I verified that the cobertura.ser
is getting cleaned up between builds.
any idea where I can get the source for that JAR?
jar and souce code for disableOptimizationsTransformation
Also - any idea how to include that JAR on classpath ONLY for the test-app build phase?
// Remove the jar before the war is bundled
grails.war.resources = { stagingDir ->
delete(file:"${stagingDir}/WEB-INF/lib/DisableOptimizationsTransformation-0.1-SNAPSHOT.jar")
}
from other post here
Same discussion also appeared in the official forum, see Branch coverage issues .
@rgarcia gave an excellent little tool jar to disable the AST optimization so that Cobertura is able to compute the coverage correctly.
To use the jar, just put it in your myapp\lib
folder and then test-app -coverage
:)
I've noticed the same thing in our grails projects - I think this is caused by the "optimization" branches the groovy compiler creates.
For example - this code
def deleteSomething(params) {
def result
if(params.something && params.somethingelse)
result = "something"
else result = "something else"
}
looks like this when compiled
public Object deleteSomething(Object params)
{
CallSite[] arrayOfCallSite = $getCallSiteArray(); Object result = null; if ((!BytecodeInterface8.isOrigZ()) || (__$stMC) || (BytecodeInterface8.disabledStandardMetaClass())) {
if (((DefaultTypeTransformation.booleanUnbox(arrayOfCallSite[2].callGetProperty(params))) && (DefaultTypeTransformation.booleanUnbox(arrayOfCallSite[3].callGetProperty(params))) ? 1 : 0) != 0) {
String str1 = "something"; result = str1; return str1; } else {
String str2 = "something else"; result = str2; return str2;
}
}
else if (((DefaultTypeTransformation.booleanUnbox(arrayOfCallSite[4].callGetProperty(params))) && (DefaultTypeTransformation.booleanUnbox(arrayOfCallSite[5].callGetProperty(params))) ? 1 : 0) != 0) {
String str3 = "something"; result = str3; return str3; } else {
String str4 = "something else"; result = str4; return str4; } return null;
}
More discussion here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With