How can I separate TestNG test execution according to Java packages?


(Sibu Abraham Thomas) #1

Hi, I have grouped my tests into 3 packages and while giving a “gradle build” all these tests run and I finally get “BUILD SUCCESS/FAILED”. What I wanted is to run the tests in these packages separately while giving build and show the status in the o/p. My gradle.build file is like this:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
  dependencies {
  compile fileTree(dir: 'lib', includes: ['*.jar'])
}
  test {
  useTestNG()
  options.suites("src/main/resources/config/testng.xml")
}

I have three packages in “src/java/tests” namely com.pack1, com.pk2 and com.pk3.

Please help.


(Szczepan Faber) #2

You have a couple of choices:

  • Use the -Dtest.single command line property to include only tests you are interested running. You can find more information about that in the user guide. Example:
./gradle test -Dtest.single=**/somePackage/**/*
  • Configure separate test tasks that have explicit includes/excludes. More info/samples in dsl:org.gradle.api.tasks.testing.Test

Example:

task myTest(type: Test) {
  include '**/foo/**/*'
  exclude '**/bar/**/*'
}
tasks.check.dependsOn myTest