ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <ste...@apache.org>
Subject Re: Extending JUnit Ant tasks
Date Mon, 11 Jun 2007 09:40:41 GMT
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


Mime
View raw message