Skip to content

Commit

Permalink
Improve TestUtil utility methods. For instrumentClasses(), you can no…
Browse files Browse the repository at this point in the history
…w specify an excludeClassesRegexList. Also, a junit() method has been added to assist with calling Ant's junit task.
  • Loading branch information
lewijw committed Jan 11, 2011
1 parent 433826b commit 3777f88
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions cobertura/test/net/sourceforge/cobertura/test/util/TestUtil.groovy
Expand Up @@ -289,26 +289,63 @@ public class TestUtil {
}
}

public instrumentClasses(ant, srcDir, datafile, todir, map=null)
public instrumentClasses(ant, srcDir, datafile, todir, map=[:])
{
def attributes = [datafile:datafile, todir:todir, failonerror:true]

map.each { key, value ->
if (key == 'ignoreAnnotationNames') return
if (key == 'excludeClassesRegexList') return
attributes.put(key, value)
}

ant.'cobertura-instrument'(attributes) {
includeClasses(regex:'mypackage.*')
map.excludeClassesRegexList.each {
excludeClasses(regex:it)
}
fileset(dir:srcDir) {
include(name:'**/*.class')
}
map?.ignoreAnnotationNames.each {
map.ignoreAnnotationNames.each {
ignoreMethodAnnotation(annotationName:it)
}
}
}

/**
* Run Ant's junit task. Typical usage:
*
* testUtil.junit(
* testClass : 'mypackage.MyTest',
* ant : ant,
* buildDir : buildDir,
* instrumentDir : instrumentDir,
* reportDir : reportDir,
* )
*
* 'ant' is the AntBuilder that is used. Instrumented classes are in
* instrumentDir; The remaining classes are in buildDir.
* An XML report is created in reportDir.
*
* @param map
* @return
*/
public junit(map) {
map.ant.junit(fork:true, dir:map.buildDir, haltonfailure:true) {
test(name:map.testClass, todir:map.reportDir)
formatter(type:'xml')
classpath {
pathelement(location:map.instrumentDir)
pathelement(location:map.buildDir)
pathelement(location:TestUtil.getCoberturaClassDir())
fileset(dir:'antLibrary/common/groovy') {
include(name:'*.jar')
}
}
}
}

/**
* Makes sure the HTML report's frame-summary.html file is accurate.
*
Expand Down

0 comments on commit 3777f88

Please sign in to comment.