Customizing JUnit reports

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Customizing JUnit reports

Rob Fletcher
Hi

I'd like to be able to make a simple customization to the JUnit
report. Specifically I want to append to
$testReportDir/stylesheet.css. If using ant:junitreport directly I
could pass the styleDir parameter and supply a custom XSL file. I
can't see any way to leverage that from Gradle, though. Since what I
want to do is so simple I thought I could just modify the file in
test.doLast. Unfortunately the modification I want to make is really
only useful when the tests fail - it makes the output clearer - and
the test.doLast closure is not run if the tests fail.

I could, I suppose, set ignoreFailures = true, do my modification then
try to detect the test state and fail, but that seems kinda hacky!

Anyone have any ideas?

Cheers,
Rob

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Customizing JUnit reports

Rene Groeschke
hi Robert,

I think the "afterSuite" closure fits here:


test{
     afterSuite{
         if(!it.parent){
             // manipulate the stylesheet file
         }
     }
}

regards,
René

--
------------------------------------
Rene Groeschke

[hidden email]
http://www.breskeby.com
http://twitter.com/breskeby
------------------------------------



Am 05.08.10 14:35, schrieb Robert Fletcher:

> Hi
>
> I'd like to be able to make a simple customization to the JUnit
> report. Specifically I want to append to
> $testReportDir/stylesheet.css. If using ant:junitreport directly I
> could pass the styleDir parameter and supply a custom XSL file. I
> can't see any way to leverage that from Gradle, though. Since what I
> want to do is so simple I thought I could just modify the file in
> test.doLast. Unfortunately the modification I want to make is really
> only useful when the tests fail - it makes the output clearer - and
> the test.doLast closure is not run if the tests fail.
>
> I could, I suppose, set ignoreFailures = true, do my modification then
> try to detect the test state and fail, but that seems kinda hacky!
>
> Anyone have any ideas?
>
> Cheers,
> Rob
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>    


--
------------------------------------
Rene Groeschke

[hidden email]
http://www.breskeby.com
http://twitter.com/breskeby
------------------------------------


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Customizing JUnit reports

Rob Fletcher
Unfortunately that event happens before the JUnit report is generated
so the file I need to manipulate won't exist yet (or will get
overwritten immediately afterwards).

On Thu, Aug 5, 2010 at 8:48 PM, Rene Groeschke <[hidden email]> wrote:

> hi Robert,
>
> I think the "afterSuite" closure fits here:
>
>
> test{
>    afterSuite{
>        if(!it.parent){
>            // manipulate the stylesheet file
>        }
>    }
> }
>
> regards,
> René
>
> --
> ------------------------------------
> Rene Groeschke
>
> [hidden email]
> http://www.breskeby.com
> http://twitter.com/breskeby
> ------------------------------------
>
>
>
> Am 05.08.10 14:35, schrieb Robert Fletcher:
>>
>> Hi
>>
>> I'd like to be able to make a simple customization to the JUnit
>> report. Specifically I want to append to
>> $testReportDir/stylesheet.css. If using ant:junitreport directly I
>> could pass the styleDir parameter and supply a custom XSL file. I
>> can't see any way to leverage that from Gradle, though. Since what I
>> want to do is so simple I thought I could just modify the file in
>> test.doLast. Unfortunately the modification I want to make is really
>> only useful when the tests fail - it makes the output clearer - and
>> the test.doLast closure is not run if the tests fail.
>>
>> I could, I suppose, set ignoreFailures = true, do my modification then
>> try to detect the test state and fail, but that seems kinda hacky!
>>
>> Anyone have any ideas?
>>
>> Cheers,
>> Rob
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>
>
> --
> ------------------------------------
> Rene Groeschke
>
> [hidden email]
> http://www.breskeby.com
> http://twitter.com/breskeby
> ------------------------------------
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>   http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Customizing JUnit reports

Adam Murdoch-3
  On 6/08/10 7:24 AM, Robert Fletcher wrote:
> Unfortunately that event happens before the JUnit report is generated
> so the file I need to manipulate won't exist yet (or will get
> overwritten immediately afterwards).

You could disable the built-in report, and use the Ant junitreport task
to generate it in the afterSuite { } closure:

test {
     testReport = false
     afterSuite {
         ant.junitreport(...)
     }
}


> On Thu, Aug 5, 2010 at 8:48 PM, Rene Groeschke<[hidden email]>  wrote:
>> hi Robert,
>>
>> I think the "afterSuite" closure fits here:
>>
>>
>> test{
>>     afterSuite{
>>         if(!it.parent){
>>             // manipulate the stylesheet file
>>         }
>>     }
>> }
>>
>> regards,
>> René
>>
>> --
>> ------------------------------------
>> Rene Groeschke
>>
>> [hidden email]
>> http://www.breskeby.com
>> http://twitter.com/breskeby
>> ------------------------------------
>>
>>
>>
>> Am 05.08.10 14:35, schrieb Robert Fletcher:
>>> Hi
>>>
>>> I'd like to be able to make a simple customization to the JUnit
>>> report. Specifically I want to append to
>>> $testReportDir/stylesheet.css. If using ant:junitreport directly I
>>> could pass the styleDir parameter and supply a custom XSL file. I
>>> can't see any way to leverage that from Gradle, though. Since what I
>>> want to do is so simple I thought I could just modify the file in
>>> test.doLast. Unfortunately the modification I want to make is really
>>> only useful when the tests fail - it makes the output clearer - and
>>> the test.doLast closure is not run if the tests fail.
>>>
>>> I could, I suppose, set ignoreFailures = true, do my modification then
>>> try to detect the test state and fail, but that seems kinda hacky!
>>>
>>> Anyone have any ideas?
>>>
>>> Cheers,
>>> Rob
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>      http://xircles.codehaus.org/manage_email
>>>
>>>
>>
>> --
>> ------------------------------------
>> Rene Groeschke
>>
>> [hidden email]
>> http://www.breskeby.com
>> http://twitter.com/breskeby
>> ------------------------------------
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Customizing JUnit reports

Adam Murdoch-3


On 6/08/10 7:31 AM, Adam Murdoch wrote:

>  On 6/08/10 7:24 AM, Robert Fletcher wrote:
>> Unfortunately that event happens before the JUnit report is generated
>> so the file I need to manipulate won't exist yet (or will get
>> overwritten immediately afterwards).
>
> You could disable the built-in report, and use the Ant junitreport
> task to generate it in the afterSuite { } closure:
>
> test {
>     testReport = false
>     afterSuite {
>         ant.junitreport(...)
>     }
> }
>

This isn't quite right. You need to check that the suite is the root
suite (otherwise you'll generate the report after each test class):

test {
     testReport = false
     afterSuite { suite ->
         if (!suite.parent) {
             ant.junitreport(...)
         }
     }
}

>
>> On Thu, Aug 5, 2010 at 8:48 PM, Rene Groeschke<[hidden email]>  
>> wrote:
>>> hi Robert,
>>>
>>> I think the "afterSuite" closure fits here:
>>>
>>>
>>> test{
>>>     afterSuite{
>>>         if(!it.parent){
>>>             // manipulate the stylesheet file
>>>         }
>>>     }
>>> }
>>>
>>> regards,
>>> René
>>>
>>> --
>>> ------------------------------------
>>> Rene Groeschke
>>>
>>> [hidden email]
>>> http://www.breskeby.com
>>> http://twitter.com/breskeby
>>> ------------------------------------
>>>
>>>
>>>
>>> Am 05.08.10 14:35, schrieb Robert Fletcher:
>>>> Hi
>>>>
>>>> I'd like to be able to make a simple customization to the JUnit
>>>> report. Specifically I want to append to
>>>> $testReportDir/stylesheet.css. If using ant:junitreport directly I
>>>> could pass the styleDir parameter and supply a custom XSL file. I
>>>> can't see any way to leverage that from Gradle, though. Since what I
>>>> want to do is so simple I thought I could just modify the file in
>>>> test.doLast. Unfortunately the modification I want to make is really
>>>> only useful when the tests fail - it makes the output clearer - and
>>>> the test.doLast closure is not run if the tests fail.
>>>>
>>>> I could, I suppose, set ignoreFailures = true, do my modification then
>>>> try to detect the test state and fail, but that seems kinda hacky!
>>>>
>>>> Anyone have any ideas?
>>>>
>>>> Cheers,
>>>> Rob
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe from this list, please visit:
>>>>
>>>>      http://xircles.codehaus.org/manage_email
>>>>
>>>>
>>>
>>> --
>>> ------------------------------------
>>> Rene Groeschke
>>>
>>> [hidden email]
>>> http://www.breskeby.com
>>> http://twitter.com/breskeby
>>> ------------------------------------
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>    http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>      http://xircles.codehaus.org/manage_email
>>
>>
>
>

--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Customizing JUnit reports

Rob Fletcher
In reply to this post by Adam Murdoch-3
Fantastic. Thanks. For future reference, I added the following to my
build.gradle:

test {
        testReport = false
        afterSuite {
                if (!it.parent) {
                        ant.project.addTaskDefinition("junitreport2",
org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator)
                        ant.junitreport2(todir: testReportDir) {
                                fileset dir: testResultsDir, includes: "TEST-*.xml"
                                report todir: testReportDir, styledir: "junitreport", format: "frames"
                        }
                }
        }
}

Trying to use ant.junitreport directly failed due to the
XMLResultAggregator not being available (although it's clearly on the
test classpth as I managed to reference it).

To make the report customizations I just copied the XSL files from
ant-junit.jar into ./junitreport and modified them as required.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Customizing JUnit reports

revas.b
This post has NOT been accepted by the mailing list yet.
Is there a new API to resolve this JUnit report customization problem, as an alternative to the solution suggested in the previous reply to use ant junitreport target ?  Any inputs would be greatly appreciated..
Reply | Threaded
Open this post in threaded view
|

Re: Customizing JUnit reports

Peter Niederwieser
This list is no longer active. Please use http://forums.gradle.org instead.