First as info: I put each @Test
in a different class (so of course each class only has 1 @Test
annotation).
Actually my goal is to want to rerun the same class with different parameter, but I want to run another class first beforehand.
I've tried to find many references that TestNG doesn't allow repeat of a class or a @Test
method annotation in one <test>
. The repeat provided is an invocationCount
function, I see about invocationCount
, but I can't achieve my goal with invocationCount
because this function repeats a @Test
at the same time and then I can run another @Test
.
public class SimpleTest1 {
@Test
@Parameters({"acc"})
public void historyTransfer(String acc) {
System.out.println(new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(Calendar.getInstance().getTime()));
}
}
public class SimpleTest2 {
@Test
@Parameters({"senderAcc", "beneficiaryAcc", "amount"})
public void tranfer(String senderAcc, String beneficiaryAcc, String amount) {
System.out.println(new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(Calendar.getInstance().getTime()));
}
}
I imagine to run like bellow configuration:
<suite name="Suite">
<test name="My Test" >
<classes>
<class name="com.SimpleTest1">
<parameter name="acc" value="11111"></parameter>
</class>
<class name="com.SimpleTest2">
<parameter name="senderAcc" value="11111"></parameter>
<parameter name="beneficiaryAcc" value="22222"></parameter>
<parameter name="amount" value="100"></parameter>
</class>
<class name="com.SimpleTest1">
<parameter name="acc" value="22222"></parameter>
</class>
</classes>
</test>
</suite>
But the above configuration didn't go as planned because the second SimpleTest1
was not executed.
Then I tried running it in a separate <test>
like bellow and success, but I'm facing new issue about delay time each <test>
.
Run multiple <test>
serially (not parallel) as follows:
<suite name="Suite">
<test name="My Test1" >
<classes>
<class name="com.SimpleTest1">
<parameter name="acc" value="11111"></parameter>
</class>
</classes>
</test>
<test name="My Test2" >
<classes>
<class name="com.SimpleTest2">
<parameter name="senderAcc" value="11111"></parameter>
<parameter name="beneficiaryAcc" value="22222"></parameter>
<parameter name="amount" value="100"></parameter>
</class>
</classes>
</test>
<test name="My Test3" >
<classes>
<class name="com.SimpleTest1">
<parameter name="acc" value="22222"></parameter>
</class>
</classes>
</test>
</suite>
TestNG Maven dependency:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0</version>
<scope>compile</scope>
</dependency>
Surefire:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
IDE : Eclipse (Version: 2018-09 (4.9.0))
OS : macOS Mojave (Version 10.14.6)
Output:
[RemoteTestNG] detected TestNG version 7.0.0
22-12-2020 21:59:32
22-12-2020 21:59:47
22-12-2020 21:59:57
===============================================
Suite
Total tests run: 3, Passes: 3, Failures: 0, Skips: 0
===============================================
But after the first <test>
is finished, there is a delay of about 10 seconds before the next <test>
runs, as well as the next test.
Note: I thought this was a problem with the IDE (I use Eclipse), but it wasn't. I've tried running it in 2 ways, via the IDE and the command line, and give me same result about this delay issue.
Via command line using this command :
mvn clean test -Dsurefire.suiteXmlFiles=testng.xml
Is there any configuration to reduce the delay time above?
See Question&Answers more detail:os