我收到错误
'Type mismatch: cannot convert from DataProvider to Annotation' error for @DataProvider (@line 19)
如有任何帮助,我们将不胜感激
package parameterization;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
public class DataProvider
{
//This test method declares that its data should be supplied by the Data Provider
// "getdata" is the function name which is passing the data
// Number of columns should match the number of input parameters
@Test(dataProvider="getData")
public void setData(String username, String password)
{
System.out.println("you have provided username as::"+username);
System.out.println("you have provided password as::"+password);
}
@DataProvider(name="getData")
public Object[][] getData()
{
//Rows - Number of times your test has to be repeated.
//Columns - Number of parameters in test data.
Object[][] data = new Object[3][2];
// 1st row
data[0][0] ="sampleuser1";
data[0][1] = "abcdef";
// 2nd row
data[1][0] ="testuser2";
data[1][1] = "zxcvb";
// 3rd row
data[2][0] ="guestuser3";
data[2][1] = "pass123";
return data;
}
}
谢谢。
最佳答案
您的类名称是DataProvider
,它隐藏了您的导入import org.testng.annotations.DataProvider
。
符合错误,你以为你用了后面的,但实际上用的是前者。
解决方案:重命名您的类或在注释中使用 FQN (@org.testng.annotations.DataProvider(name="getData")
)。
关于java - 类型不匹配 : cannot convert from DataProvider to Annotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45304563/