If property doesn't match, why Gradle keeps building my TestNG @Test methods?

(kendo) #1


I have 2 TestNG Classes:


DashboardTest will just System.out.println(“DASHBOARD”);
Dummy will just System.out.println(“DUMMY”);

I have build.gradle file , looks like this

def suite1 = project.hasProperty("DASHBOARD") && project.hasProperty("DUMMY")

test {
    useTestNG() {
    dependsOn cleanTest
    useDefaultListeners = true

    if(suite1 == true) {
        suites ("./src/test/java/testng.xml")


suites ("./src/test/java/testng.xml") will execute both Dashboard and Dummy.

The problem is when I try to build the project using gradle clean build -Pwhatever , it will execute both DASHBOARD and DUMMY . I can see the build report in project folder / build/ reports/ tests/ test / index.html . I would expected when I put any properties other than -PDASHBOARD and -PDUMMY , none of my @Test will be executed. :sweat_smile:

  1. Is it possible to force gradle to follow the property -P ? If the property doesn’t match or doesn’t exist , then do not execute suites ("./src/test/java/testng.xml") (i.e. do nothing , do not run any @Test). In my current case, if the property doesn’t match or doesn’t exist, Gradle will just build everything.

  2. I then try to delete my testng.xml file , and surprisingly I still see the same result in the html build report. Would Gradle build the whole classes in project folder without testng.xml file ? I thought Gradle must check the testng.xml file in order to know what @Test classes need to be build & run ?