A little while ago, I mentioned that I'd been investigating groovy for work stuff; I'm now doing lots of process/automation/integration work with it.
One of my first steps has been test automation, and boy had I been missing the ability to run automated unit/integration tests with a single command! It feels really silly to suddenly remember a classic pattern that I just hadn't been using in a while, but that was extraordinarily useful in other contexts. What was I thinking? Here, then, because it's so darned useful I don't want to forget it, is my "smoke script" for groovy:
#!/usr/bin/env groovy
import junit.framework.*
static Test suite() {
def suite = new TestSuite();
def gcl = new GroovyClassLoader();
def testdir = 'src/test/groovy';
gcl.addClasspath(testdir);
def ant = new AntBuilder();
def pattern = "Test";
def files = ant.fileScanner {
fileset (dir:testdir) {
include(name:"**/*${pattern}*.groovy")
exclude(name:"**/*Helper*.groovy")
exclude(name:"**/*Abstract*.groovy")
}
};
files.each {
suite.addTestSuite(gcl.parseClass(new File(it.path)));
};
return suite;
}
junit.textui.TestRunner.run(suite());
Comments