Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestNG DataProvider and CitrusResource injection of TestRunner not working properly #83

Closed
ceazy79 opened this Issue Mar 11, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@ceazy79
Copy link
Contributor

ceazy79 commented Mar 11, 2016

Scenario:

Trying to use TestNG DataProvider together with TestRunner resource injection in order to use the runner in a thread-safe way.

Testcase:

`public class DataProviderTest extends TestNGCitrusTest {

private static final Logger log = LoggerFactory.getLogger(DataProviderTest.class);

@DataProvider(name = "getTestData")
public Object[][] getTestData() {
    String[][] result = new String[][] { { "hello" } };
    return result;
}

@Test(testName = "dataProviderAndCitrusResourceInjectionTest",
        enabled = true,
        dataProvider = "getTestData")
@CitrusTest(name = "dataProviderAndCitrusResourceInjectionTest")
@CitrusParameters({"dataRecord" })
@Parameters({"dataRecord", "runner" })
public void dataProviderAndCitrusResource(String dataRecord, @Optional @CitrusResource TestRunner runner) throws Exception {
    runner.echo("Hello Citrus Test World.");
    log.info("DataProvider dataRecord = " + dataRecord);
}

} `

Expected result:

TestRunner executes echo action and log contains string "DataProvider dataRecord = hello"

Actual result:

org.testng.TestNGException:
The data provider is trying to pass 1 parameters but the method de.finkonsens.geco.citrus.DataProviderTest#dataProviderAndCitrusResource takes 2 and TestNG is unable in inject a suitable object

at org.testng.internal.Invoker.injectParameters(Invoker.java:1253)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1122)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at org.testng.internal.Invoker.injectParameters(Invoker.java:1249)
... 21 more

Kind regards,
Chris

@christophd

This comment has been minimized.

Copy link
Member

christophd commented Mar 16, 2016

Fixed it and you should be able to use it like this:

Testcase:

public class DataProviderTest extends TestNGCitrusTest {

    private static final Logger log = LoggerFactory.getLogger(DataProviderTest.class);

    @DataProvider(name = "getTestData")
    public Object[][] getTestData() {
        String[][] result = new String[][] { { "hello", null } };
        return result;
    }

    @Test(testName = "dataProviderAndCitrusResourceInjectionTest",
        enabled = true,
        dataProvider = "getTestData")
    @CitrusTest(name = "dataProviderAndCitrusResourceInjectionTest")
    @Parameters({"dataRecord", "runner" })
    public void dataProviderAndCitrusResource(String dataRecord, @CitrusResource TestRunner runner) throws Exception {
        runner.echo("Hello Citrus Test World.");
        log.info("DataProvider dataRecord = " + dataRecord);
    }
} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.