我有团队合作的工作,分2个步骤:
1.执行测试。
2.重新运行失败。
我们在第1步中有3个测试失败,并且在重新运行后只有1个测试失败。
Teamcity生成的报告具有4个失败的测试而不是1个。如何通过合格状态覆盖第1步的失败测试结果?
编辑
例如,我的套房看起来像这样:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite 1" thread-count="5" parallel="methods">
<test name="Test 1">
<classes>
<class name="unittest.TestNGTest"/>
</classes>
</test>
</suite>
Java代码:
import org.testng.Assert;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestNGTest {
@AfterMethod
public void afterMethod() {
System.out.println(Thread.currentThread().getId() + " afterMethod");
}
@BeforeMethod
public void beforeMethod() {
System.out.println(Thread.currentThread().getId() + " beforeMethod");
}
@DataProvider
public Object[][] dp1() {
return new Object[][]{
{1},{2}
};
}
@Test(dataProvider = "dp1")
public void testM1(int param) {
Assert.assertTrue(param > 3);
}
@DataProvider
public Object[][] dp2() {
return new Object[][]{
{1},{2},{3},{4},{5},{6},{7}
};
}
@Test(dataProvider = "dp2")
public void testM2(int param) {
Assert.assertFalse(param == 7);
}
}
运行后,我的代码生成了重新运行测试套件,teamcity在第二步中运行了该套件:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite 1" thread-count="1" parallel="methods">
<test name="Test 1">
<parameter name="indicies" value = "0:1"/> <-- that means that i want rerun only first and second dataprovider configuration -->
<classes>
<class name="unittest.TestNGTest">
<include name = testM1/>
</class>
</classes>
</test>
<test name="Test 2">
<parameter name="indicies" value = "6"/> <-- that means that i want rerun only seventh dataprovider configuration -->
<classes>
<class name="unittest.TestNGTest">
<include name = testM2/>
</class>
</classes>
</test>
</suite>
如您所见,我仅在一个线程中使用相应的dataprovider配置重新运行失败的测试用例