使用DataProvider参数化的JGiven失败,"方法'名称'应该没有参数"

Dex*_*ter 4 java bdd spring-integration junit4 jgiven

我正在为我的测试工作JGiven框架(已经是一个大粉丝!).我使用@DataProvider时遇到了问题

我正在浏览文档http://jgiven.org/docs/parameterizedscenarios/, 但是我收到以下错误

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)
Run Code Online (Sandbox Code Playgroud)

我的Test类如下

@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()
            ...;
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

Jan*_*fer 5

为了使用DataProvider,您必须使用.注释测试类@RunWith( DataProviderRunner.class).这在JGiven示例中不可见(我将相应地调整文档以使其更清晰).有关如何使用数据提供者的更多详细信息,请参阅https://github.com/TNG/junit-dataprovider/wiki/Getting-started#usage.

更新:我刚刚看到你已经使用了spring junit runner.这意味着您不能使用dataprovider运行器,因为您不能在junit中为同一个测试类使用两个运行器.虽然没有弹簧junit转轮可以执行弹簧测试,但这是一个不同的主题;-)

Update2:dataprovider运行器的wiki描述了如何一起使用spring和dataprovider runner:https://github.com/TNG/junit-dataprovider/wiki/Tips-and-Tricks#dataprovider-for-spring-integration-testing