public class FactoryTest {
@Test
@Parameters("Row")
public void run1(int row) throws MalformedURLException{
new Controller(row);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="methods">
<test thread-count="2" name="factory test" parallel="methods">
<classes>
<class name="RealPackage.FactoryTest">
<methods>
<include name="run1">
<parameter name="Row" value="1"/>
</include>
</methods></class>
</classes>
</test> <!-- OfficialTestName -->
</suite> <!-- Suite -->
这是我需要运行的测试之一的示例。我需要它与其他测试并行运行。因此,在测试中,run1()
我创建了一个Controller(row)
启动测试的方法,并将行号传递给它。我想同时运行new Controller(1)
andnew Controller(2)
和new Controller(3)
等。如果我将 java 文件更改为此,我可以做到这一点:
public class OfficialTest {
@Test
public void run1() throws MalformedURLException{
new Controller(1);
}
@Test
public void run2() throws MalformedURLException{
new Controller(2);
}
@Test
public void run3() throws MalformedURLException{
new Controller(3);
}
@Test
public void run4() throws MalformedURLException{
new Controller(4);
}
@AfterMethod
public void close() {
System.out.println("closing");
}
}
但这不是动态的。我需要能够使用row
. 所以我在想也许我可以生成一个 XML 文件来处理这个问题,但我仍然不确定它是否能够以这种方式并行运行。