Java 为每个<;测试>;在TestNG中
首先作为信息:我将每个Java 为每个<;测试>;在TestNG中,java,testng,Java,Testng,首先作为信息:我将每个@Test放在不同的类中(当然每个类只有一个@Test注释) 实际上,我的目标是想用不同的参数重新运行同一个类,但我想先运行另一个类 我试图找到许多TestNG不允许在一个中重复类或@Test方法注释的引用。提供的repeat是一个invocationCount函数,我了解了invocationCount,但是我不能用invocationCount实现我的目标,因为这个函数同时重复一个@Test,然后我可以运行另一个@Test public class SimpleTest
@Test
放在不同的类中(当然每个类只有一个@Test
注释)
实际上,我的目标是想用不同的参数重新运行同一个类,但我想先运行另一个类
我试图找到许多TestNG不允许在一个
中重复类或@Test
方法注释的引用。提供的repeat是一个invocationCount
函数,我了解了invocationCount
,但是我不能用invocationCount
实现我的目标,因为这个函数同时重复一个@Test
,然后我可以运行另一个@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()));
}
}
我想象着像下面的配置一样运行:
<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>
TestNG Maven依赖项:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0</version>
<scope>compile</scope>
</dependency>
但是在第一次
完成后,在下一次
运行以及下一次测试之前,会有大约10秒的延迟
注意:我认为这是IDE的问题(我使用Eclipse),但事实并非如此。我试过通过IDE和命令行以两种方式运行它,并给出了关于延迟问题的相同结果
通过命令行使用此命令:
mvn clean test -Dsurefire.suiteXmlFiles=testng.xml
是否有任何配置可减少上述延迟时间?您可以使用此处所述的注释设置优先级或对其他方法的依赖性: 检查@Test.priority或@Test.dependson方法
这样做,将允许您依次连续运行测试。我不知道为什么您需要在单独的测试中运行同一个测试类,但在启动测试时,它可能会加载所有相关的上下文,这可能需要时间,在测试结束后,它可能需要关闭一些资源,两者都可能需要时间/ 您可以使用来使用延迟原因的更多详细信息(并添加更多日志以查看计时)
详细级别为0到10,其中10是最详细的。
将其设置为10后,您将看到控制台输出将包含有关测试、方法和侦听器等的信息
为了加快进程,您还可以使用TestNG的特性
threadPoolSize属性允许您指定应为此执行分配多少线程
首先,套件不是一个测试计划(顺便说一句,它可能是一个很好的特性请求),而是一种选择测试的方法。这意味着您不能定义测试之间的依赖关系。这就是为什么拥有相同的测试类不起作用(它应该失败或创建不同的实例) 据我所知,最好的方法是将您自己的逻辑及其与测试框架的集成分开:
<suite name="Suite">
<test name="My Test" >
<classes>
<class name="com.SimpleTest">
<methods>
<include name="step1">
<parameter name="acc" value="11111"></parameter>
</methods>
<methods>
<include name="step2">
<parameter name="senderAcc" value="11111"></parameter>
<parameter name="beneficiaryAcc" value="22222"></parameter>
<parameter name="amount" value="100"></parameter>
</methods>
<methods>
<include name="step3">
<parameter name="acc" value="22222"></parameter>
</methods>
</class>
</classes>
</test>
</suite>
(免责声明:我没有对照dtd检查XML,可能是错误的,但您有这个想法)
命名或创建装置的方式取决于您自己的约定。请向人们提供更多信息。如果您没有使用SimpleTest做什么,我们将毫无帮助您在这两个测试中运行SimpleTest的是什么?尝试在套件中使用
“verbose=“10”
,以获取更多信息details@user7294900仅包含一个@Test注释,带有代码System.out.println(“Test”)代码>仅此而已,没有其他内容。我的问题不清楚吗?试着用
运行,为什么需要在两个测试中使用相同的测试类?也许延迟是因为每天都加载上下文Test@Tea我已经更新了问题以获取更多信息。感谢您的回复,但此答案尚未回答问题:)啊,好的-您想减少测试运行之间的延迟-您已经连续运行测试了?在这种情况下,忽略上面的答案…是否确定执行延迟是由于TestNG调度,而不是由于您的测试套件/案例中配置的一些先前的测试设置-您可以提供有关您的测试案例的更多详细信息吗?嗨,我更新了问题以获取更多信息。太好了,您还可以提供输出/日志吗?从中您可以推断testng在测试运行之间暂停了10秒。抱歉,谢谢您的回答,但我认为我应该更新问题以更好地解释我目前面临的问题。您好,我已经更新了问题以获取更多信息。@frianH您是否添加了verbose=10并在那里看到了时间花费?是的,我尝试了verbose=10
,每次都得到了相同的结果(大约10秒):(登录更多详细信息。您好@juherr谢谢您的回答。顺便说一句,您能再次帮助我解决另一个问题吗?如果您有时间和设计,请访问此帖子:
<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>
[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
===============================================
mvn clean test -Dsurefire.suiteXmlFiles=testng.xml
<suite name="Suite" verbose="10">
public class SimpleClass1 {
public void historyTransfer(String acc) {
System.out.println(new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(Calendar.getInstance().getTime()));
}
}
public class SimpleClass2 {
public void tranfer(String senderAcc, String beneficiaryAcc, String amount) {
System.out.println(new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(Calendar.getInstance().getTime()));
}
}
public class SimpleTest {
@Test
@Parameters({"acc"})
public void step1(String acc) {
(new SimpleClass1()).historyTransfer(acc);
}
@Test(dependsOnMethods = {"step1"})
@Parameters({"senderAcc", "beneficiaryAcc", "amount"})
public void step2(String senderAcc, String beneficiaryAcc, String amount) {
(new SimpleClass2()).transfer(acc);
}
@Test(dependsOnMethods = {"step2"})
@Parameters({"acc"})
public void step3(String acc) {
(new SimpleClass1()).historyTransfer(acc);
}
}
<suite name="Suite">
<test name="My Test" >
<classes>
<class name="com.SimpleTest">
<methods>
<include name="step1">
<parameter name="acc" value="11111"></parameter>
</methods>
<methods>
<include name="step2">
<parameter name="senderAcc" value="11111"></parameter>
<parameter name="beneficiaryAcc" value="22222"></parameter>
<parameter name="amount" value="100"></parameter>
</methods>
<methods>
<include name="step3">
<parameter name="acc" value="22222"></parameter>
</methods>
</class>
</classes>
</test>
</suite>