In gradle 4.6, how to force all tests in a class gets executed first before moving to tests in next class?



  • I am using Gradle 4.6 with testng. My test suite has tests organized something like these.

    java class1 { test 1.1 test 1.2 test 1.3 test 1.4 }

    java class2 java class3 java class4 java class5

    All these classes have total 100 tests in the suite. When I execute the suite, gradle first executes, tests 1.1 and 1.2 and then goes and executes all the tests in class2 to 5 and finally comes back to class 1 to execute 1.3 and 1.4.

    Is there a way we can force all the tests in a class to be executed before going to class? For example, it will be helpful, I get all my tests in class1 completes execution, then goes to next class (in any order) and so on.

    I do not want to set dependency as any failures will force the dependent test to skip, these are independent tests, eventhough there is some dependency declared tests within the same class.



  • As far as I know, Gradle does not control the execution order. Instead use the TestNG priority annotation.

    example:

    @Test(priority=0)
    public void test1(){
    
    System.out.println("First Test");
    }
    
    
    @Test(priority=1)
    public void test2(){
    
    System.out.println("Second Test");
    }
    

    And maybe set the order for classes in Testng.xml e.g here.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2