Wed Aug 8 12:33:57 EDT 2007

runtests.groovy

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());

Posted by dan | Permanent link | File under: tech

Comments


At Wed Oct 3 20:51:51 2007, palinode said:
Every time I see the word groovy in your code, I hear Bruce Campbell's voice. Now I've got lines from the Evil Dead movies stuck in my brain.

Add a Comment

Name
Prove you're a human:
What is four plus three?
(What is this?)
Note: HTML won't work in comments. Just type plain text.