You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Alex Ruiz <al...@gmail.com> on 2007/06/10 21:38:17 UTC

Extending JUnit Ant tasks

Hello all,

I've been trying to extend JUnit's report without success. The following are
some questions/comments about what I couldn't accomplish:

1. Ant's
org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter does
not offer any support for extensibility. It would be nice to have some
methods we could override to add some extra XML elements to the generated
XML report. For example, we can have the method 'protected void
onFailureOrError(Test test, Throwable error, Element errorElement)' which
can be overriden by users and add some extra elements to the XML element
containing the error information. Note that this method should not change
the behavior of XMLJUnitResultFormatter, it just lets users add extra
error/failure info.

2. In the same class it would be nice to have access to the XML document
(may be a protected getter?)

3. The method 'getTestCaseClassName(Test)' in '
org.apache.tools.ant.taskdefs.optional.junit.JUnitVersionHelper' is package
protected. Can it be changed to public?

4. I'm using my own XSL files for the junit report task. The problem is that
I need to hook up my own XSL extensions. This is what I have:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="
1.0"
    xmlns:lxslt="http://xml.apache.org/xslt"
    xmlns:redirect="http://xml.apache.org/xalan/redirect"
    xmlns:java="http://xml.apache.org/xslt/java"
    xmlns:stringutils="xalan://org.apache.tools.ant.util.StringUtils"
    extension-element-prefixes="redirect">

and in the body of the XSL file I have:
    <xsl:value-of select="java:
org.fest.swing.junit.ImageHandler.decodeBase64AndSaveAsPng(string($encoded.image),
string($screenshot.fullpath))"/>

and when running my Ant build I get the following:
[junitreport] Loading stylesheet
C:\fest\fest-swing-junit\src\main\java\org\fest\swing\junit\junit-frames.xsl
[junitreport] : Error! Cannot find class 'org.fest.swing.junit.ImageHandler
'.
[junitreport] : Error! Cannot find external method '
org.fest.swing.junit.ImageHandler.decodeBase64AndSaveAsPng' (must be
public).
[junitreport] : Fatal Error! Could not compile stylesheet

I haven't found a way to specify my own class in the junitreport tag. Any
suggestions?

Any help will be greatly appreciated!

Thanks!
-Alex.

Re: Extending JUnit Ant tasks

Posted by Steve Loughran <st...@apache.org>.
Steve Loughran wrote:

> The alternative is for ant to optionally register a signal handler (sun 
> java only; would cause trouble on IDEs) and then to shut down more 
> gracefully on termination. This is what smartfrog does, though since 
> Java6 the javac compiler goes out of its way to tell us off for doing so 
> ("you are using sun internal apis that may go away in future").

For the curious, it says this:

     [javac] 
/home/slo/Projects/SmartFrog/Forge/core/smartfrog/src/org/smartfrog/sfcore/processcompound/InterruptHandlerImpl.java:95: 
warning: sun.misc.Signal is Sun proprietary API and may be removed in a 
future release
     [javac]             oldHandler=Signal.handle(new Signal(name), this);
     [javac]                        ^
     [javac] Note: Some input files use or override a deprecated API.
     [javac] Note: Recompile with -Xlint:deprecation for details.
     [javac] 7 warnings

There's no obvious way to turn it off...possibly theres an 
@SuppressWarnings annotation which makes your app java1.5+ only. 
Whatever it is, its annoying, and there is no alternative way to 
implement signal handlers, so I dont see why sun should be telling us off.

-steve


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Extending JUnit Ant tasks

Posted by Steve Loughran <st...@apache.org>.
Rebhan, Gilbert wrote:
>  
> 
> 
> -----Original Message-----
> From: Steve Loughran [mailto:stevel@apache.org] 
> Sent: Monday, June 11, 2007 12:41 PM
> To: Ant Users List
> Subject: Re: Extending JUnit Ant tasks
> 
> 
> Hi,
> 
> /*
> well, sounds like you have to write a new xmllogger. One problem with a 
> streaming/flushing logger is that if the process died, the output is 
> still invald XML; the XSL engine would bail out.
> */
> 
> /*
> yup, you're right. As our process uses the xmllogger only to present
> the logfiles (not processed with xslt, just the raw xmllogfile) in a
> browser
> window, it would be no help, as browser would cough because of 
> invalid xml, but finally it's better than a 0 byte logfile.
> */

yes, you can at least do by-hand diagnostics.

> 
> /*
> Better to find out why your scripts are hanging and kill that. I always 
> timeout my exec/java and junit runs, and dont have to kill ant itself. 
> Have you tried that?
> */
> 
> hm, it's a generic worklflow that start ant scripts and waits for
> reponse = Failed or Successful; as there are other jobs
> in the queue you have to set a timeout to finish off a hanging job.



> 
> /*
> The alternative is for ant to optionally register a signal handler (sun 
> java only; would cause trouble on IDEs) and then to shut down more 
> gracefully on termination.
> */
> 
> thanks for the pointer, i already have downloaded smartfrog 3.10.0000
> but had no time to take a detailled look
> 

I'm trying to release 3.11 beta 1 this week, so dont invest too much 
time until then.



> /*
> There is not  yet any equivalent for the xmllogger, but it is something 
> that could be written if you want to help with it.
> */
> 
> i've found a contribution =
> 
> http://confluence.public.thoughtworks.org/display/CC/AntDirectXmlLogger
> 
> but =
> 
> : Direct XML Logger
> call ant -listener org.apache.tools.ant.DirectXmlLogger
> -DXmlLogger.file=Y:/antxmlout.xml -f %1
> 
> gives me a NullPointerException
> i never wrote a logger for ant, maybe i try to write my own or fix the
> DirectXmlLogger
> when time allows

well, if they can do it, so can we; it would be good for something that 
bamboo and luntbuild could also handle. Really those tools should bypass 
the XML and go for something more intimate; perhaps even serialized java 
objects. Relying on XML output of ant and junit is easy, but not that 
real-time.

-steve

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Extending JUnit Ant tasks

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 


-----Original Message-----
From: Steve Loughran [mailto:stevel@apache.org] 
Sent: Monday, June 11, 2007 12:41 PM
To: Ant Users List
Subject: Re: Extending JUnit Ant tasks


Hi,

/*
well, sounds like you have to write a new xmllogger. One problem with a 
streaming/flushing logger is that if the process died, the output is 
still invald XML; the XSL engine would bail out.
*/

/*
yup, you're right. As our process uses the xmllogger only to present
the logfiles (not processed with xslt, just the raw xmllogfile) in a
browser
window, it would be no help, as browser would cough because of 
invalid xml, but finally it's better than a 0 byte logfile.
*/

/*
Better to find out why your scripts are hanging and kill that. I always 
timeout my exec/java and junit runs, and dont have to kill ant itself. 
Have you tried that?
*/

hm, it's a generic worklflow that start ant scripts and waits for
reponse = Failed or Successful; as there are other jobs
in the queue you have to set a timeout to finish off a hanging job.

/*
The alternative is for ant to optionally register a signal handler (sun 
java only; would cause trouble on IDEs) and then to shut down more 
gracefully on termination.
*/

thanks for the pointer, i already have downloaded smartfrog 3.10.0000
but had no time to take a detailled look

/*
There is not  yet any equivalent for the xmllogger, but it is something 
that could be written if you want to help with it.
*/

i've found a contribution =

http://confluence.public.thoughtworks.org/display/CC/AntDirectXmlLogger

but =

: Direct XML Logger
call ant -listener org.apache.tools.ant.DirectXmlLogger
-DXmlLogger.file=Y:/antxmlout.xml -f %1

gives me a NullPointerException
i never wrote a logger for ant, maybe i try to write my own or fix the
DirectXmlLogger
when time allows


Regards, Gilbert


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Extending JUnit Ant tasks

Posted by Steve Loughran <st...@apache.org>.
Rebhan, Gilbert wrote:
>  
> Hi,
> 
> -----Original Message-----
> From: Steve Loughran [mailto:stevel@apache.org] 
> Sent: Monday, June 11, 2007 11:41 AM
> To: Ant Users List
> Subject: Re: Extending JUnit Ant tasks
> 
> 
> /*
> [ ... ]
> In them I show an XHTML output that gets streamed out... not only is it 
> viewable without waiting for the end of the run, you can stil XSL over 
> it and a system crash will leave a half complete file. 
> [ ... ]
> /*
> 
> that's the bad thing about xmllogger too, we run our ant scripts similar
> to CruiseControl with a timeout set and xmllogger.
> If a script hits the timeout nothing is written, there's no logfile. If
> it would be written
> as it comes we would have a half complete file, would be fine.
> 
> /*
> [ ... ]
>  But I would like to 
> improve the XML output we generate with
> [ ... ]
> */
> 
> Will there also be a patch for xmllogger available ?
> 

well, sounds like you have to write a new xmllogger. One problem with a 
streaming/flushing logger is that if the process died, the output is 
still invald XML; the XSL engine would bail out.

Better to find out why your scripts are hanging and kill that. I always 
timeout my exec/java and junit runs, and dont have to kill ant itself. 
Have you tried that?

The alternative is for ant to optionally register a signal handler (sun 
java only; would cause trouble on IDEs) and then to shut down more 
gracefully on termination. This is what smartfrog does, though since 
Java6 the javac compiler goes out of its way to tell us off for doing so 
("you are using sun internal apis that may go away in future").

What will be in ant1.7.1 is a 'big project logger' that provides better 
log output for running a big project (with many subant/ant calls) -it 
tells you when you enter and exit child projects, prefixes each target 
with the name of the project, and skips targets which dont do any work 
(though I may make that configurable by an ant property). There is not 
yet any equivalent for the xmllogger, but it is something that could be 
written if you want to help with it.

-steve

-steve

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Extending JUnit Ant tasks

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 
Hi,

-----Original Message-----
From: Steve Loughran [mailto:stevel@apache.org] 
Sent: Monday, June 11, 2007 11:41 AM
To: Ant Users List
Subject: Re: Extending JUnit Ant tasks


/*
[ ... ]
In them I show an XHTML output that gets streamed out... not only is it 
viewable without waiting for the end of the run, you can stil XSL over 
it and a system crash will leave a half complete file. 
[ ... ]
/*

that's the bad thing about xmllogger too, we run our ant scripts similar
to CruiseControl with a timeout set and xmllogger.
If a script hits the timeout nothing is written, there's no logfile. If
it would be written
as it comes we would have a half complete file, would be fine.

/*
[ ... ]
 But I would like to 
improve the XML output we generate with
[ ... ]
*/

Will there also be a patch for xmllogger available ?


Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Extending JUnit Ant tasks

Posted by Steve Loughran <st...@apache.org>.
Alex Ruiz wrote:
> Hello all,
> 
> I've been trying to extend JUnit's report without success. The following 
> are
> some questions/comments about what I couldn't accomplish:
> 
> 1. Ant's
> org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter does
> not offer any support for extensibility. It would be nice to have some
> methods we could override to add some extra XML elements to the generated
> XML report. For example, we can have the method 'protected void
> onFailureOrError(Test test, Throwable error, Element errorElement)' which
> can be overriden by users and add some extra elements to the XML element
> containing the error information. Note that this method should not change
> the behavior of XMLJUnitResultFormatter, it just lets users add extra
> error/failure info.
> 
> 2. In the same class it would be nice to have access to the XML document
> (may be a protected getter?)

I'm reluctant to do this, as I dont want to end up supporting 
XMLJUnitResultFormatter as a stable bit of Ant's API.

In particular, I dont think the idea of building up a DOM as we 
currently do is the right way forward. It doesnt scale and the result of 
a big test is complete loss of data

You may just want to fork off the entire class and keep it alive 
yourself; that way we wont break anything.

If you are interested in what I am thinking of result formatting, have a 
look at the presentation and video I did last year.:

http://smartfrog.org/presentations/distributed_testing_with_smartfrog_slides.pdf
http://smartfrog.org/autolinks/googleLTAC06.htm

In them I show an XHTML output that gets streamed out... not only is it 
viewable without waiting for the end of the run, you can stil XSL over 
it and a system crash will leave a half complete file. Oh, and
  -log levels get recorded...rather than a simple text output, we are 
capturing commons-logging level log events
  -logs can get collected from >1 machine
  -tests can run in different processes and hosts from the test listener.

I've done all of this work in the SmartFrog deployment framework, and I 
cant add the distributed system features to Ant. But I would like to 
improve the XML output we generate with

-streaming to file instead of building a fat DOM
-support for the extra outcomes of TestNG and JUnit4
-extra metadata associated with tests (machine info, test info)
-ability to give test results new titles, text information, etc ,etc

I have been way to busy to start on this, but would like to soonish, 
just as soon as I have a little product release out the way. Adidng 
better support for subclassing of a reworked result formatter (which 
would live alongside the existing one) would be nice. We also need to 
provide a way to provide test-time configuration data to the result 
formatters, which is not there today.


> 
> 3. The method 'getTestCaseClassName(Test)' in '
> org.apache.tools.ant.taskdefs.optional.junit.JUnitVersionHelper' is package
> protected. Can it be changed to public?

It's already public in SVN_HEAD, which means when Ant 1.7.1 ships 
everyone sees it.

> 
> 4. I'm using my own XSL files for the junit report task. The problem is 
> that
> I need to hook up my own XSL extensions. This is what I have:
> 
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="
> 1.0"
>    xmlns:lxslt="http://xml.apache.org/xslt"
>    xmlns:redirect="http://xml.apache.org/xalan/redirect"
>    xmlns:java="http://xml.apache.org/xslt/java"
>    xmlns:stringutils="xalan://org.apache.tools.ant.util.StringUtils"
>    extension-element-prefixes="redirect">
> 
> and in the body of the XSL file I have:
>    <xsl:value-of select="java:
> org.fest.swing.junit.ImageHandler.decodeBase64AndSaveAsPng(string($encoded.image), 
> 
> string($screenshot.fullpath))"/>

cool screenshots. The selenium author does flash videos of entire 
sessions, to make life really interesting.

> 
> and when running my Ant build I get the following:
> [junitreport] Loading stylesheet
> C:\fest\fest-swing-junit\src\main\java\org\fest\swing\junit\junit-frames.xsl 
> 
> [junitreport] : Error! Cannot find class 'org.fest.swing.junit.ImageHandler
> '.
> [junitreport] : Error! Cannot find external method '
> org.fest.swing.junit.ImageHandler.decodeBase64AndSaveAsPng' (must be
> public).
> [junitreport] : Fatal Error! Could not compile stylesheet
> 
> I haven't found a way to specify my own class in the junitreport tag. Any
> suggestions?

Never been any need for it. Junit report is really a variation on XSLT; 
if the <style> task doesnt help, then you will need to extend 
junitreport to take a new classpath.

-steve

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org