如何将DataProvider与批量对象一起使用(TestNG)

时间:2017-11-09 11:16:43

标签: java automated-tests testng dataprovider testng-dataprovider

你可以帮我解决我的问题。

我正在运行testNG UT。代码 dataProvider 是:

@DataProvider(name = "inputData")
    private Object[][] createInputData() {

        return new Object[][] {
            {new Object1 (1, "string", "string", ObjectX, false), Object2, Object3, false, 3},
            {new Object1 (1, "string", "string", ObjectX, true), Object2, Object3, false, 2},
            {new Object1 (1, "string", "string", ObjectX, false), Object2, Object3, false, 35}
        };
    }

测试代码:

@Test(dataProvider = "inputData")
    public void test(final Object1 o1, final Object2 o2, final Object3 o3, final boolean b, final int i) {
...
}

当我尝试运行它时,我收到异常:

test(...)
java.lang.RuntimeException: Can't invoke method public void (...) on this instance of class ...TestClass_$$_jvste22_0 due to class mismatch
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:73)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:696)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:882)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1189)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
        at org.testng.TestRunner.privateRun(TestRunner.java:767)
        at org.testng.TestRunner.run(TestRunner.java:617)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
        at org.testng.SuiteRunner.run(SuiteRunner.java:254)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
        at org.testng.TestNG.run(TestNG.java:1057)
        at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:295)
        at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:84)
        at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:90)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
你可以告诉我我做错了什么。

0 个答案:

没有答案