我有3个测试类:
FirstTest:
public class FirstTest {
@BeforeClass(alwaysRun = true)
public void setUp() {
System.out.println("FirstTest: set up class");
}
@Test(groups = "FirstTest")
public void test1() {
System.out.println("FirstTest: test1");
}
@Test(groups = "FirstTest")
public void test2() {
System.out.println("FirstTest: test2");
}
@Test(
groups = "FirstTest",
dependsOnMethods = "test2"
)
public void test3() {
System.out.println("FirstTest: test3");
}
@Test(
groups = {"FirstTest", "first:4"},
dependsOnMethods = "test3"
)
public void test4() {
System.out.println("FirstTest: test4");
}
@AfterClass(alwaysRun = true)
public void tearDown() {
System.out.println("FirstTest: tear down class");
}
}
SecondTest:
public class SecondTest {
@BeforeClass(alwaysRun = true)
public void setUp() {
System.out.println("SecondTest: set up class");
}
@Test(groups = "SecondTest")
public void test1() {
System.out.println("SecondTest: test1");
}
@Test(groups = "SecondTest")
public void test2() {
System.out.println("SecondTest: test2");
}
@Test(
dependsOnGroups = "first:4",
groups = "SecondTest"
)
public void test3() {
System.out.println("SecondTest: test3");
}
@Test(groups = "SecondTest")
public void test4() {
System.out.println("SecondTest: test4");
}
@AfterClass(alwaysRun = true)
public void tearDown() {
System.out.println("SecondTest: tear down class");
}
}
OtherTest:
public class OtherTest {
@BeforeClass(alwaysRun = true)
public void setUp() {
System.out.println("OtherTest: set up class");
}
@Test(groups = "OtherTest")
public void test1() {
System.out.println("OtherTest: test1");
}
@Test(groups = "OtherTest")
public void test2() {
System.out.println("OtherTest: test2");
}
@Test(groups = "OtherTest")
public void test3() {
System.out.println("OtherTest: test3");
}
@Test(groups = "OtherTest")
public void test4() {
System.out.println("OtherTest: test4");
}
@AfterClass(alwaysRun = true)
public void tearDown() {
System.out.println("OtherTest: tear down class");
}
}
我想在多个线程中运行它们 - 每个类一个线程。在不传递整个测试类之前,不应中断每个类的运行测试以执行其他测试。但我有以下结果(例如一个线程):
的testng.xml:
<suite name="Suite1" parallel="classes" thread-count="1" verbose="10">
<test name="sample" preserve-order="true" >
<classes>
<class name="sample.testng.FirstTest" />
<class name="sample.testng.SecondTest" />
<class name="sample.testng.OtherTest" />
</classes>
</test>
</suite>
实际结果:
sample.testng.SecondTest.setUp() 21480956
sample.testng.SecondTest.test4() 21480956
sample.testng.SecondTest.test1() 21480956
sample.testng.SecondTest.test2() 21480956
sample.testng.OtherTest.setUp() 32782069
sample.testng.OtherTest.test4() 32782069
sample.testng.OtherTest.test1() 32782069
sample.testng.OtherTest.test3() 32782069
sample.testng.OtherTest.test2() 32782069
sample.testng.OtherTest.tearDown() 32782069
sample.testng.FirstTest.setUp() 2623667
sample.testng.FirstTest.test1() 2623667
sample.testng.FirstTest.test2() 2623667
sample.testng.FirstTest.test3() 2623667
sample.testng.FirstTest.test4() 2623667
sample.testng.FirstTest.tearDown() 2623667
sample.testng.SecondTest.test3() 21480956
sample.testng.SecondTest.tearDown() 21480956
如何获得下一个结果?
sample.testng.SecondTest.setUp() 21480956
sample.testng.SecondTest.test4() 21480956
sample.testng.SecondTest.test1() 21480956
sample.testng.SecondTest.test2() 21480956
sample.testng.SecondTest.test3() 21480956
sample.testng.SecondTest.tearDown() 21480956
sample.testng.OtherTest.setUp() 32782069
sample.testng.OtherTest.test4() 32782069
sample.testng.OtherTest.test1() 32782069
sample.testng.OtherTest.test3() 32782069
sample.testng.OtherTest.test2() 32782069
sample.testng.OtherTest.tearDown() 32782069
sample.testng.FirstTest.setUp() 2623667
sample.testng.FirstTest.test1() 2623667
sample.testng.FirstTest.test2() 2623667
sample.testng.FirstTest.test3() 2623667
sample.testng.FirstTest.test4() 2623667
sample.testng.FirstTest.tearDown() 2623667
答案 0 :(得分:0)
如果你想运行1. SecondTest 2. OtherTest 3. FirstTest,正如你在最终列表中所概述的那样,为什么你使用保留顺序列出的类
<class name="sample.testng.FirstTest" />
<class name="sample.testng.SecondTest" />
<class name="sample.testng.OtherTest" />
而不是
<class name="sample.testng.SecondTest" />
<class name="sample.testng.OtherTest" />
<class name="sample.testng.FirstTest" />
答案 1 :(得分:0)
您需要增加thread-count = 3
<suite name="Suite1" parallel="classes" thread-count="3" verbose="10">
<test name="sample" preserve-order="false" >
<classes>
<class name="sample.testng.FirstTest" />
<class name="sample.testng.SecondTest" />
<class name="sample.testng.OtherTest" />
</classes>
</test>
</suite>
当你说要并行运行3个测试类时,你只传递1个线程。