未检测到第二注释:
@Test(dataProvider = "getData")
public void bankUser(String userName, String password) {
}
@DataProvider // ==> Error : @DataProvider is not an annotation type
public Object[][] getData() {
Object [] [] data = new Object[3][2];
data[0][0] = "firstUsername";
data[0][1] = "firstPassword";
data[1][0] = "secondUsername";
data[1][1] = "secondPassword";
data[2][0] = "thirdUsername";
data[2][1] = "thirdPassword";
return data;
}
我只导入了一个软件包:
import org.testng.annotations.Test;
如何解决此问题?
答案 0 :(得分:0)
将此添加到Maven中:
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
示例:
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class Demo
{
@Test(dataProvider = "getData")
public void bankUser(String userName, String password) {
}
@DataProvider(name = "getData")
public Object[][] getData() {
Object [] [] data = new Object[3][2];
data[0][0] = "firstUsername";
data[0][1] = "firstPassword";
data[1][0] = "secondUsername";
data[1][1] = "secondPassword";
data[2][0] = "thirdUsername";
data[2][1] = "thirdPassword";
return data;
}
}
注意:如何使用键盘快捷键在Eclipse中导入:
Ctrl + Shift + O