Using the TestRunner

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Using the TestRunner

hlopez
Hello,

I'm trying to use the test runner but I am getting this exception:

[Utils] [ERROR] [Error] org.testng.TestNGException:
Cannot inject @Test annotated Method [runnerTest] with [interface com.consol.citrus.dsl.runner.TestRunner].

Code looks like this:
@Test
public class MyJavaWayTest extends TestNGCitrusTest {

    @Test
    @CitrusTest(name = "SendMessageWithJava")
    public void runnerTest(@CitrusResource TestRunner runner) {
        runner.echo("Running java mode!");

Do I need to create a bean of the TestRunner somewhere so it can get injected, or will Citrus create it for me?

Cheers
Reply | Threaded
Open this post in threaded view
|

Re: Using the TestRunner

hlopez
I'm getting the same error with this peace of code:

import com.consol.citrus.annotations.CitrusResource;
import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;
import org.testng.annotations.Test;

@Test
public class MyJavaWayTest extends TestNGCitrusTestRunner {

    @CitrusTest
    public void runnerTest(@CitrusResource TestContext context) {
        context.setVariable("myVaralbe", "some value 1");
        echo("${myVariable}");
    }
}

2017-10-24 16:48:22 [main] INFO  com.consol.citrus.Citrus -
[Utils] [ERROR] [Error] org.testng.TestNGException:
Cannot inject @Test annotated Method [runnerTest] with [class com.consol.citrus.context.TestContext].
For more information on native dependency injection please refer to http://testng.org/doc/documentation-main.html#native-dependency-injection
        at org.testng.internal.Parameters.checkParameterTypes(Parameters.java:244)
Reply | Threaded
Open this post in threaded view
|

Re: Using the TestRunner

Christoph Deppisch
Administrator
This is because TestNG does not know about this parameter and raises this error. TestNG also provides parameter injection. So you need to mark this parameter as @Optional. In addition to that you need to give a parameter name with @Parameter annotation:

public class ResourceInjectionIT extends TestNGCitrusTestRunner {

    @Test 
    @Parameters("context")
    @CitrusTest
    public void resourceInjectionIT(@Optional @CitrusResource TestContext context) {
        context.setVariable("myVariable", "some value");
        echo("${myVariable}");
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: Using the TestRunner

Christoph Deppisch
Administrator
Same with TestRunner parameter injection
Reply | Threaded
Open this post in threaded view
|

Re: Using the TestRunner

hlopez
In reply to this post by Christoph Deppisch
Thanks,

I must have missed that somewhere in the documentation.

H