Xray-App / xray-testng-extensions

Enhanced TestNG integration with Xray Test Management for Jira
MIT License
9 stars 4 forks source link

How to use gradle test task with useTestNG() to generate enhanced XML reports? #17

Open itkhanz opened 4 months ago

itkhanz commented 4 months ago

Hi, we are using gradle with TestNG to run our tests as gradle clean test.

In the documentation, you suggest to run a custom task to allow this extension to produce enhanced TestNG xml reports as below: https://github.com/Xray-App/xray-testng-extensions?tab=readme-ov-file#2b-configure-gradle-to-use-testng-xmlreporter-and-enable-user-defined-test-attributes

task testngTest(type: JavaExec, dependsOn: [classes]) {
    group 'Verification'
    description 'Run TestNG tests'
    mainClass = 'org.testng.TestNG'
    args('testng.xml', '-reporter',
            'org.testng.reporters.XMLReporter:generateTestResultAttributes=true,generateGroupsAttribute=true'
    )
    classpath = sourceSets.test.runtimeClasspath
}

However, this solution is not really compatible for our use case since we have a lot of custom code in our gradle test task, so ideally we want this extenion to work from gradle test task itself where i can pass this additional argument:-

-reporter org.testng.reporters.XMLReporter:generateTestResultAttributes=true,generateGroupsAttribute=true

test {
   useTestNG() {
     useDefaultListeners = true
   }
}

Isn't it possible to achieve it somehow via options closure, args or like for example: jvmArgs '-reporter', 'org.testng.reporters.XMLReporter:generateTestResultAttributes=true,generateGroupsAttribute=true'

I came across this old thread, where it was mentioned that it was not really possible to achieve this using Gradle test task:- https://groups.google.com/g/testng-users/c/CqTNqaPeAQY

I am not sure whether this limitations still exists? or we can now achieve this in gradle test task without having to write a custom task?

Relevant resources: 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

bitcoder commented 3 months ago

I'm not sure; I played with gradle already some time ago. I remember that there were some limitations.. that led me to create a task instead of using the default test task. Back then, a few tutorials were made and are available on this GH repo.

itkhanz commented 3 months ago

I reached out to Gradle and TestNG team on this, and this turned out to be the limitation of TestNG API that Gradle uses. This feature request is still open at the Gradle side. I hope someone from Gradle team picks up this request, and it will then be possible to use Gradle test task for this extension. see https://github.com/gradle/gradle/issues/29135 https://github.com/gradle/gradle/issues/18828