ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vitezslav Stejskal <vitezslav.stejs...@czech.sun.com>
Subject [PATCH] for Ant's JUnit task
Date Sun, 25 Feb 2001 14:35:33 GMT
Hi all,

I realized troubles with junit task running in separate (fork="yes")
JVM.
The JUnitTestRunner's main function executed on separate JVM
instantiates
JUnitTest object and sets it up from arguments passed through the
command
line. Everything looks fine untill you need to know the output file
originally
set for the test (outfile attribute in test element of junit task). I
needed it in
my own formatter, which writes links to files produced by the test and
tries
to make them relative to the location, where the output file is palced
to.

As long as I get the instance of JUnitTest object to my formatter I read

the output file by the call of JUnitTest.getOutfile, which works fine,
when running in the same JVM, where the original junit task was created,

but stops to work when task is forked (call of getOutfile always returns
null).

I used following code in JUnitTask and JUnitTestRunner classes to pass
absolute path of output file to the JUnitTest object in forked JVM.

Could you, please, include it in the Ant's source code repository,
to make it available in next version.

Thanks,
Vita


----
file: org\apache\tools\ant\taskdefs\optional\junit\JUnitTask.java
function: public void execute()

                CommandlineJava cmd = (CommandlineJava)
commandline.clone();


cmd.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");

// PATCH - begin
                File fff = project.resolveFile(test.getOutfile());
                cmd.createArgument().setValue(test.getName() + "," +
fff.getAbsolutePath());
// PATCH - end

                cmd.createArgument().setValue("haltOnError="
                                              + test.getHaltonerror());
                cmd.createArgument().setValue("haltOnFailure="
                                              +
test.getHaltonfailure());
                if (summary) {
                    log("Running " + test.getName(), Project.MSG_INFO);


cmd.createArgument().setValue("formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter");

                }

----
file: org\apache\tools\ant\taskdefs\optional\junit\JUnitTestRunner.java
function: public static void main(String args[])

// PATCH - begin
        StringTokenizer tok = new StringTokenizer(args[0], ",");
        JUnitTest t = new JUnitTest(tok.nextToken());
        if (tok.hasMoreTokens())
            t.setOutfile(tok.nextToken());
// PATCH - end

        JUnitTestRunner runner = new JUnitTestRunner(t, haltError,
haltFail);
        transferFormatters(runner);
        runner.run();
        System.exit(runner.getRetCode());




--
Vitezslav Stejskal, Software engineer

SUN Microsystems Czech s.r.o.
e-mail: vitezslav.stejskal@czech.sun.com
tel:    +420 2 3300-9232



Mime
View raw message