【发布时间】:2016-06-23 20:59:34
【问题描述】:
我正在尝试运行使用 Mockito 的 JUnit Cucumber 测试。这是我遇到的问题。在我的 Cucumber Runner 课程中,我有
@RunWith(Cucumber.class)
在我的常规 JUnit 测试中,我有
@RunWith(Mockito.class)
鉴于我一次只能有一个 @RunWith,我如何将 Mockito 与 Cucumber 结合使用?
【问题讨论】:
我正在尝试运行使用 Mockito 的 JUnit Cucumber 测试。这是我遇到的问题。在我的 Cucumber Runner 课程中,我有
@RunWith(Cucumber.class)
在我的常规 JUnit 测试中,我有
@RunWith(Mockito.class)
鉴于我一次只能有一个 @RunWith,我如何将 Mockito 与 Cucumber 结合使用?
【问题讨论】:
是的,您可以同时使用 Cucumber 和 Mockito。
您不能同时使用两个 JUnit 运行器。但是,如果您将 Mockito 作为依赖项添加到您的项目并像这样创建您的模拟:List mockedList = mock(List.class); 那么您应该能够组合这些工具。
更多信息请访问http://mockito.org/
【讨论】:
您可以使用 JUnit 规则而不是使用 @RunWith 来运行 Mockito,以便您可以将 @RunWith 与另一个 JUnit 运行器一起使用。
//@RunWith(MockitoJUnitRunner.class)
@RunWith(AnotherRunner.class)
public class TestSomething {
@Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
MyMock myMock;
...
}
【讨论】: