# How to inject properties into JUnit XML output file with Test task?

**URL:** <https://discuss.gradle.org/t/how-to-inject-properties-into-junit-xml-output-file-with-test-task/6462>\
**Category:** Old Forum Archive\
**Created:** [May 14, 2012, 3:34pm UTC](https://discuss.gradle.org/t/how-to-inject-properties-into-junit-xml-output-file-with-test-task/6462 "2012-05-14T15:34:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ingineering](https://avatars.discourse-cdn.com/v4/letter/i/bc8723/32.png) [@ingineering](https://discuss.gradle.org/u/ingineering)\
**Post date:** [May 14, 2012, 3:34pm UTC](https://discuss.gradle.org/t/how-to-inject-properties-into-junit-xml-output-file-with-test-task/6462/1 "2012-05-14T15:34:00Z")

</div>

If I run a Spock test from Ant, all the ant property values are injected into the testsuite/properties element in the Junit XML output. If I run it from Gradle, testsuite/properties is empty. How can I cause properties to be emitted in the XML? I’m happy to set those properties myself (understanding that there will not be any ant properties since ant’s not being used). Tried adding a systemProperty but that didn’t show up.

Using gradle 1.0-rc-3 with groovy 1.8.6 and spock 0.6.

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [May 15, 2012, 5:53am UTC](https://discuss.gradle.org/t/how-to-inject-properties-into-junit-xml-output-file-with-test-task/6462/2 "2012-05-15T05:53:00Z")

</div>

There’s currently no way to do this.

What’s your use case for wanting to populate the properties?

---

<div class="post-metadata">

**Author:** ![ingineering](https://avatars.discourse-cdn.com/v4/letter/i/bc8723/32.png) [@ingineering](https://discuss.gradle.org/u/ingineering)\
**Post date:** [May 15, 2012, 12:12pm UTC](https://discuss.gradle.org/t/how-to-inject-properties-into-junit-xml-output-file-with-test-task/6462/3 "2012-05-15T12:12:00Z")

</div>

Trying to switch from Ant to Gradle as part of a larger tool chain that expects to find information in properties. Could do it via XSLT post-processing, but that seems clumsy vs. sticking with pure Groovy. Given the properties element is present, just empty, it doesn’t seem too wildly off in the weeds to want to put things there, similarly to the way Ant does.

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [May 15, 2012, 12:17pm UTC](https://discuss.gradle.org/t/how-to-inject-properties-into-junit-xml-output-file-with-test-task/6462/4 "2012-05-15T12:17:00Z")

</div>

What properties do you need though? How are they being used by downstream tooling? I’d like to understand why it’s needed.

---

<div class="post-metadata">

**Author:** ![ingineering](https://avatars.discourse-cdn.com/v4/letter/i/bc8723/32.png) [@ingineering](https://discuss.gradle.org/u/ingineering)\
**Post date:** [May 15, 2012, 2:25pm UTC](https://discuss.gradle.org/t/how-to-inject-properties-into-junit-xml-output-file-with-test-task/6462/5 "2012-05-15T14:25:00Z")

</div>

Downstream tool uploads the JUnit XML file into a QA reporting database. Expects to find [ant.project.name](http://ant.project.name) in the properties section so it can associate the results with the correct project. I am a Gradle early adopter in my org, surrounded by Ant. Good news is people who are seeing my Gradle usage are liking it. In general the notion of some level of “Ant compatibility” in this area seems sensible to me. Things like JVM and JUnit configuration values in the properties section could be useful.

---

<div class="post-metadata">

**Author:** ![ingineering](https://avatars.discourse-cdn.com/v4/letter/i/bc8723/32.png) [@ingineering](https://discuss.gradle.org/u/ingineering)\
**Post date:** [May 16, 2012, 4:11pm UTC](https://discuss.gradle.org/t/how-to-inject-properties-into-junit-xml-output-file-with-test-task/6462/6 "2012-05-16T16:11:00Z")

</div>

As a workaround, I created a simple method that uses replaceAll to inject a property element for [ant.project.name](http://ant.project.name) into the properties element for each testsuite in the consolidated JUnit report. I call it during afterSuite.
