Run Cucumber test with Mockito

泄露秘密 提交于 2019-12-12 10:59:39

问题


I'm trying to run a JUnit Cucumber test that uses Mockito. Here's the issue I'm running into. In my Cucumber Runner class, I have

@RunWith(Cucumber.class)

And in my regular JUnit tests I have

@RunWith(Mockito.class)

Given that I can only have one @RunWith at a time, how can I use Mockito in conjunction with Cucumber?


回答1:


Yes, you can use Cucumber and Mockito at the same time.

You can't use two JUnit runners at the same time. But if you add Mockito as a dependency to your project and create your mocks like this: List mockedList = mock(List.class); then you should be able to combine the tools.

More information is availabe at http://mockito.org/




回答2:


You can run Mockito using JUnit rule instead of using @RunWith so that you can use @RunWith with another JUnit runner.

//@RunWith(MockitoJUnitRunner.class)
@RunWith(AnotherRunner.class)
public class TestSomething {
    @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();

    @Mock
    MyMock myMock;
    ...
}


来源:https://stackoverflow.com/questions/38001759/run-cucumber-test-with-mockito

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!