简体   繁体   中英

How can I run multiple test methods multiple times in a loop

public class OrionTripCreation extends GeneratePayload {
    
    String route_set_id = null;
    String warehouse_name = null;
    String transaction_id = null;
    String lr_number = null; 
    String bid_id = null;
    String message = null;
    String transaction_status = null;
    String trip_status = null;
    String payment_Id = null;
    String oracle_id = null;
    String intermittent_payment_id = null;
    String intermittent_oracle_id = null;
        
    OrionUtility orion = new OrionUtility();

     @Test(invocationCount = 10)
    
      public void generateLR() throws Exception { 
         lr_number =orion.generateLRNumber();
          ExtentTestManager.getTest().log(LogStatus.INFO,"LR Number is generated :-" + lr_number);    
      }
     
     @Test 
      public void raiseIndent() throws Exception { 
          transaction_id =orion.raiseIndent(); 
          ExtentTestManager.getTest().log(LogStatus.INFO,"Indent is created :-" + transaction_id);
          trip_status = orion.fetchStatusForTransaction("requested" , transaction_id);
      
      }
...
}

I tried using @Test(invocationCount = n) , but it runs only that method multiple times, I want to run all the methods once and then run the test second time

This is TestNG question and I will use a simple example to illustrate it.

  • Test class
package demo;

import org.testng.annotations.Test;

public class MultipleTest {

    @Test
    public void testName() {
        System.out.println("tess 1");
    }

    @Test
    public void testName2() {
        System.out.println("tess 2");
    }
}
  • Test suite xml: src/test/resources/testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
    <test name="exampletest1">
        <classes>
            <class name="demo.MultipleTest" />
        </classes>
    </test>
</suite>
  • Run TestNG file from main method:
public class AppDemo {

    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            List<String> suites = List.of("src/test/resources/testng.xml");
            TestNG tng = new TestNG();
            tng.setTestSuites(suites);
            tng.run();
        }
    }
}

It will run all tests 3 times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM