Hi,
I am running my TestNG test suite via gradle clean test and have my build.gradle configured as below to generate TestNG XML reports:
test {
useTestNG() {
useDefaultListeners = true
}
}
I would like to use a library which adds additional attributes to produced TestNG XML reports and suggest to use custom task to achieve this because apparently gradle does not allow us to set attributes on the XMLReporter used by TestNG.
task testngTest(type: JavaExec, dependsOn: [classes]) {
description 'Run TestNG tests'
mainClass = 'org.testng.TestNG'
args('testng.xml', '-reporter',
'org.testng.reporters.XMLReporter:generateTestResultAttributes=true,generateGroupsAttribute=true'
)
classpath = sourceSets.test.runtimeClasspath
}
I would like to ask whether we can still achieve the above functionality using test task provided by gradle itself? I do not want to create a custom task for this purpose and run my tests via gradle clean compileJava testngTest
. What I want is to pass this option to TestNG from the test task itself and run my tests as usual with gradle clean test
I also checked out the documentation of gradle API, and the useTestNG options but I could not figure out the way to pass this commandline argument -reporter org.testng.reporters.XMLReporter:generateTestResultAttributes=true,generateGroupsAttribute=true
to TestNG.
In Maven, there is the possibiliy to achieve this using maven surefire plugin as follows:
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>reporter</name>
<value>org.testng.reporters.XMLReporter:generateTestResultAttributes=true</value>
</property>
</properties>
</configuration>
</plugin>
...
</plugins>
</build>
Could you please let me know whether this is at all possible to achieve using Gradle test task and useTestNG()?
references:
https://groups.google.com/g/testng-users/c/CqTNqaPeAQY
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html
https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/testng/TestNGOptions.html
https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html