在我的报告中,excel表格中的最后一个测试名称将被附加到我的结果中。以下是我的代码
public class Test_suite implements ITest {
private String testInstanceName="";
public String getTestName()
{
return testInstanceName;
}
private void setTestName(String anInstanceName)
{
this.testInstanceName = anInstanceName;
}
@DataProvider()
public Object[][] Unit() throws Exception
{
Object[][] testObjArray = Excel.getTableArray("./Test Data/Test.xlsx","Unit");
return (testObjArray);
}
@BeforeMethod(alwaysRun=true)
public void before(Method method,Object[] parameters)
{
String testCaseId="";
testCaseId = parameters[0].toString();
System.out.println(testCaseId);
setTestName(testCaseId);
}
@Test(dataProvider="Unit")
public void Test(){
}我的报告是这样的

发布于 2018-03-24 12:50:34
这是因为所有使用dataProvider的测试都将并行执行。使用的默认线程数是10。如您所见,这些方法使用类的相同部分,在本例中为Test_suite.java
insance变量testInstanceName是可变的,每个dataprovider线程都会覆盖它,并使用最新的变量设置为测试名称。您可以通过在之前的方法中包含set test name逻辑而不使用实例变量来实现您想要做的事情
发布于 2018-03-28 13:33:43
package API_Testing;
import java.lang.reflect.Method;
import org.testng.ITest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import resources.Excel;
import resources.Utils;
public class Carto implements ITest{
private String testInstanceName="";
public String getTestName()
{
return testInstanceName;
}
@DataProvider
public Object[][] Data() throws Exception
{
Object[][] testObjArray = Excel.getTableArray("./Test_Cases/Test_Cases.xlsx","Carto");
return (testObjArray);
}
@BeforeMethod(alwaysRun=true)
public void before(Method method,Object[] parameters)
{
String testCaseId="";
testCaseId = parameters[0].toString();
this.testInstanceName=testCaseId;
}
@Test(dataProvider="Data")
public void Test(String TCname,String Type,String API,String Input,String Input_Path,String Validator,String Output,String Output_value )throws Exception
{
Utils util=new Utils();
Output_value=Output_value.substring(1,Output_value.length()-1);
util.Test_body(Type, API, Input, Input_Path, Validator, Output, Output_value);
}
}现在我的代码是这样的,输出和我之前上传的一样。没有变化
https://stackoverflow.com/questions/49448311
复制相似问题