I am working on JGiven framework for my tests (already a big fan!). I have an issue though working with @DataProvider
I was going through the documentation http://jgiven.org/docs/parameterizedscenarios/ but I get the following error
java.lang.Exception: Method test_update_order should have no parameters
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java:76)
at org.junit.runners.ParentRunner.validatePublicVoidNoArgMethods(ParentRunner.java:155)
at org.junit.runners.BlockJUnit4ClassRunner.validateTestMethods(BlockJUnit4ClassRunner.java:
208)
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.j
ava:188)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunn
er.java:128)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassR
unner.java:111)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorIm
pl.java:45)
My Test class is as follows
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=Application.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
@Story( { "JIRA-123" } )
@Description("Story: coffee shop")
public class CoffeeShopTest extends ScenarioTest<GivenSomeState, WhenSomeAction, ThenSomeOutcome> {
@Test @Issue( { "OUI-1156"} )
@Description("Test for update order for coffee shop")
@DataProvider( {
"1",
"3",
"2",
} )
public void test_update_order(int coffee) {
given()
...
when()
...
then()
...;
}
}
Thank You!
In order to use the DataProvider you have to annotate the test class with the @RunWith( DataProviderRunner.class)
. This is not visible in the JGiven example (I will adapt the documentation accordingly to make that clearer). For more details about how to use the dataprovider see https://github.com/TNG/junit-dataprovider/wiki/Getting-started#usage.
Update: I just saw that you already use the spring junit runner. This means that you cannot use the dataprovider runner as you cannot use two runners in junit for the same test class. It is possible to execute spring tests without the spring junit runner though, but this is a different topic ;-)
Update2: The wiki of the dataprovider runner describes how to use spring and the dataprovider runner together: https://github.com/TNG/junit-dataprovider/wiki/Tips-and-Tricks#dataprovider-for-spring-integration-testing