且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TestNG - 无法让@Factory 工作

更新时间:2023-02-05 21:40:50

首先,Factory 应该返回一个一维的 Object 数组.并且该工厂方法应该返回您尝试执行的测试类的实例.

First of all ,a Factory should return a one dimension Object array. And that factory method should return instances of the test class that you are trying to execute.

所以工厂会运行你的测试,如果你改成这个

So the factory will run your tests, if you change to this

public class MyFactory {
    @Factory
    public Object[] dp() {
        Object[] data = new Object[] {
            new MyTest("1", "TestCase1", "Sample test 1"), new Mytest("1", "TestCase1", "Sample test 1"), new MyTest("1", "TestCase1", "Sample test 1")
        };
        return data;
    }
}