为 ant junit batchtest 指定文件名

Specifying filenames for ant junit batchtest

我有一个正在运行的 ant-task,它以下列方式运行我的一批 junit-tests:

<junit printsummary="yes" showoutput="yes" haltonfailure="no">
    <formatter type="plain" />
    <classpath>
        <path refid="app.compile.classpath" />
        <path id="classes" location="${app.classes.home}" />
        <path id="test-classes" location="${app.build.home}/test-classes" />
    </classpath>
    <batchtest fork="no" todir="${app.tests.reports}">
        <fileset dir="${app.tests.home}">
            <include name="**/*Test*.java" />
        </fileset>
    </batchtest>
</junit>

现在这工作正常,除了生成的测试报告的名称。这些名称过长并遵循以下模式:

TEST-com.company.package.Class.txt

有没有办法为 batchtest 的报告文件指定文件命名模式,最好是 ant 1.6.5?

我知道对于单个测试,您可以使用 outfile 属性指定文件名。在junit-task reference中,只是说明:

It then generates a test class name for each resource that ends in .java or .class.

不,这不可能。

根据源码

protected void execute(JUnitTest arg, int thread) throws BuildException {
    validateTestName(arg.getName());

    JUnitTest test = (JUnitTest) arg.clone();
    test.setThread(thread);

    // set the default values if not specified
    //@todo should be moved to the test class instead.
    if (test.getTodir() == null) {
        test.setTodir(getProject().resolveFile("."));
    }

    if (test.getOutfile() == null) {
        test.setOutfile("TEST-" + test.getName());
    }

    // execute the test and get the return code
    TestResultHolder result = null;
    if (!test.getFork()) {
        result = executeInVM(test);
    } else {
        ExecuteWatchdog watchdog = createWatchdog();
        result = executeAsForked(test, watchdog, null);
        // null watchdog means no timeout, you'd better not check with null
    }
    actOnTestResult(result, test, "Test " + test.getName());
}

如果您没有在 test 元素中明确指定,它将创建输出文件 "TEST-" + test.getName()。无法在 batchtest 元素中指定它。