parallel="methods" thread-count="2" 您请求TestNG 在线程中运行每个Method,在parallel 中,使用2 个线程池。因此这可以解释ABCABC
需要考虑的几点:
<suite> 标记上的parallel 属性可以采用以下值之一:
<suite name="My suite" parallel="methods" thread-count="5">
<suite name="My suite" parallel="tests" thread-count="5">
<suite name="My suite" parallel="classes" thread-count="5">
<suite name="My suite" parallel="instances" thread-count="5">
parallel="methods": TestNG will run all your test methods in separate threads. Dependent methods will also run in separate threads but they will respect the order that you specified.
parallel="tests": TestNG will run all the methods in the same <test> tag in the same thread, but each <test> tag will be in a separate thread. This allows you to group all your classes that are not thread safe in the same <test> and guarantee they will all run in the same thread while taking advantage of TestNG using as many threads as possible to run your tests.
parallel="classes": TestNG will run all the methods in the same class in the same thread, but each class will be run in a separate thread.
parallel="instances": TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will be running in different threads.
在您的情况下,因为您的方法似乎不是线程安全的,所以我建议您使用 thread-count="1",或者只需查看上面的选项,看看如果您真的想要什么最适合您在parallel 模式下运行。
<suite name="Testing 07ZR" parallel="methods" thread-count="1">
或不处于并行模式:
<suite name="Testing 07ZR">
如果您希望同一个 TestClass 中的方法以特定顺序运行,您也可以使用 priority:
priority 此测试方法的优先级。较低的优先级将
优先安排。
例子:
@Test(priority=1)
public void Test1() {
}
@Test(priority=2)
public void Test2() {
}
@Test(priority=3)
public void Test3() {
}
然后它们会依次运行,分别为Test1、Test2、Test3。
https://testng.org/doc/documentation-main.html#test-groups