Discussion:
Customizing JUnit reports
Robert Fletcher
2010-08-05 12:35:48 UTC
Permalink
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
Rene Groeschke
2010-08-05 19:48:17 UTC
Permalink
hi Robert,

I think the "afterSuite" closure fits here:


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

regards,
René
--
------------------------------------
Rene Groeschke

rene-So656aZnn7pWk0Htik3J/***@public.gmane.org
http://www.breskeby.com
http://twitter.com/breskeby
------------------------------------
Post by 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
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
------------------------------------
Rene Groeschke

rene-So656aZnn7pWk0Htik3J/***@public.gmane.org
http://www.breskeby.com
http://twitter.com/breskeby
------------------------------------
Robert Fletcher
2010-08-05 21:24:05 UTC
Permalink
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).
Post by Rene Groeschke
hi Robert,
test{
   afterSuite{
       if(!it.parent){
           // manipulate the stylesheet file
       }
   }
}
regards,
René
--
------------------------------------
Rene Groeschke
http://www.breskeby.com
http://twitter.com/breskeby
------------------------------------
Post by 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
---------------------------------------------------------------------
    http://xircles.codehaus.org/manage_email
--
------------------------------------
Rene Groeschke
http://www.breskeby.com
http://twitter.com/breskeby
------------------------------------
---------------------------------------------------------------------
  http://xircles.codehaus.org/manage_email
Adam Murdoch
2010-08-05 21:31:29 UTC
Permalink
Post by Robert 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).
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(...)
}
}
Post by Robert Fletcher
Post by Rene Groeschke
hi Robert,
test{
afterSuite{
if(!it.parent){
// manipulate the stylesheet file
}
}
}
regards,
René
--
------------------------------------
Rene Groeschke
http://www.breskeby.com
http://twitter.com/breskeby
------------------------------------
Post by 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
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
------------------------------------
Rene Groeschke
http://www.breskeby.com
http://twitter.com/breskeby
------------------------------------
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
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
Adam Murdoch
2010-08-05 22:58:11 UTC
Permalink
Post by Adam Murdoch
Post by Robert 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).
You could disable the built-in report, and use the Ant junitreport
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(...)
}
}
}
Post by Adam Murdoch
Post by Robert Fletcher
Post by Rene Groeschke
hi Robert,
test{
afterSuite{
if(!it.parent){
// manipulate the stylesheet file
}
}
}
regards,
René
--
------------------------------------
Rene Groeschke
http://www.breskeby.com
http://twitter.com/breskeby
------------------------------------
Post by 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
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
------------------------------------
Rene Groeschke
http://www.breskeby.com
http://twitter.com/breskeby
------------------------------------
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
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
Robert Fletcher
2010-08-05 23:06:12 UTC
Permalink
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.
Peter Niederwieser
2013-10-01 09:01:51 UTC
Permalink
This list is no longer active. Please use http://forums.gradle.org instead.



--
View this message in context: http://gradle.1045684.n5.nabble.com/Customizing-JUnit-reports-tp2265269p5711913.html
Sent from the gradle-user mailing list archive at Nabble.com.

Loading...