Julian
Julian

Reputation: 4085

Gradle configuring TestNG and JUnit reports dirs

I am relatively new to gradle and we use both JUnit and testNG unit tests in our project. With google help I figured out how to make both testNG and JUnit tests running. Below is how I ended up by achieving it

build.gradle
....    
task testNG(type: Test) {
    useTestNG {}
}

test {
    dependsOn testNG
}

However only the JUnit reports are produced. Google again helped me with this link https://discuss.gradle.org/t/using-junit-and-testng-together-steps-on-testng-html-file/5484 which shows how to solve a problem that looks exactly like mine by configuring two separate test reports folders like below:

testng.testReportDir = file("$buildDir/reports/testng")
test.testReportDir = file("$buildDir/reports/testjunit")

However it does not exactly say where to put those two entries and I feel like I am going to get crazy trying to look at gradle books, gradle examples and API without figuring out how to. According with the API test task has a reports property where you can configure TestTaskReports instance but whatever I tried failed. Can you please help me with this. It must be something so obvious that I am missing it.

Thank you in advance

Upvotes: 6

Views: 3093

Answers (1)

Rene Groeschke
Rene Groeschke

Reputation: 28663

Take a look at the DSL reference for Test. There you can find a reports property at https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:reports This gives you a TestTaskReports. Following this route in the DSL leads you to:

task testNG(type: Test) {
    useTestNG {}
    reports.html.destination = file("$buildDir/reports/testng")
}

test {
    reports.html.destination = file("$buildDir/reports/test")

    dependsOn testNG
}

Upvotes: 5

Related Questions