与DataProvider绑定时,Testng @Factory方法失败

时间:2014-10-14 19:30:31

标签: java testng

我有一个testng DataProvider和Factory注释类,它根据数据提供者提供的各种数据动态执行测试类。

这是课程:

DataProvider
==================
@DataProvider (name="GenericDataProvider", parallel=true) 
public static Object[][] genericDP(Method method, ITestContext context) throws Exception{

    Map<String,String> arguments = DataProviderUtils.resolveDataProviderArguments(method);
    List<Map<String,String>> valList = null;

    if (arguments.containsKey("propFile")) {
        String file = arguments.get("propFile");
        InputStream stream = BaseDataProvider.class.getClassLoader().getResourceAsStream(file);
        TestUtilities testUtil = new TestUtilities();
        valList = testUtil.parseXML(testUtil.getStringFromInputStream(stream), "dataset");
    }

    return new Object[][] { { valList } };
}

The Factory class
=====================
@Factory
@Test(dataProviderClass=BaseDataProvider.class, dataProvider="GenericDataProvider")
@DataProviderArguments({"propFile=psgITest.xml"} )
public void runMultipleAccountProvisioningTestsWithDifferentUniversityPartners(List<Map<String,String>> datasets) {

    String partner = null;
    String source = null;

    for (Map<String,String> dataset : datasets) {
        for (String data : dataset.keySet()) {
            if ("partner".equalsIgnoreCase(data)) {
                partner = dataset.get(data);
            } else if ("source".equalsIgnoreCase(data)) {
                source = dataset.get(data);
            }

            if (null != partner && null != source) {
                new com.example.psgITestAccountProvisioning001(partner, source);
                new com.example.psgITestAccountProvisioning002(partner, source);
            }
        }
    }
}

psgITest.xml是以下格式的属性文件

<?xml version="1.0" encoding="UTF-8"?>
<data>
<dataset>
<partner>abc</partner>
<source>xyz</source>
</dataset>
</data>


Exception
================
org.testng.TestNGException: 

工厂方法类com.example.psgITestAccountProvisioning.runMultipleAccountProvisioningTestsWithDifferentUniversityPartners()抛出异常     at org.testng.internal.FactoryMethod.invoke(FactoryMethod.java:93)     在org.testng.internal.TestNGClassFinder。(TestNGClassFinder.java:140)     at org.testng.TestRunner.initMethods(TestRunner.java:409)     在org.testng.TestRunner.init(TestRunner.java:235)     在org.testng.TestRunner.init(TestRunner.java:205)     在org.testng.TestRunner。(TestRunner.java:160)     at org.testng.remote.RemoteTestNG $ 1.newTestRunner(RemoteTestNG.java:141)     at org.testng.remote.RemoteTestNG $ DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:271)     at org.testng.SuiteRunner $ ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:561)     在org.testng.SuiteRunner.init(SuiteRunner.java:157)     在org.testng.SuiteRunner。(SuiteRunner.java:111)     at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)     在org.testng.TestNG.createSuiteRunners(TestNG.java:1286)     在org.testng.TestNG.runSuitesLocally(TestNG.java:1140)     在org.testng.TestNG.run(TestNG.java:1057)     at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)     在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)     在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) 引起:java.lang.NullPointerException     at org.testng.internal.FactoryMethod.invoke(FactoryMethod.java:82)     ......还有17个

知道出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

遇到了问题。 Factory方法的返回类型应为Object []