【发布时间】:2016-07-08 14:17:41
【问题描述】:
在使用@Mock 和@InjectMocks 注释的通常模拟中,被测类应该使用@RunWith(MockitoJUnitRunner.class) 运行。
@RunWith(MockitoJUnitRunner.class)
public class ReportServiceImplTestMockito {
@Mock
private TaskService mockTaskService;
@InjectMocks
private ReportServiceImpl service;
// Some tests
}
但在某些示例中,我看到 @RunWith(PowerMockRunner.class) 被使用:
@RunWith(PowerMockRunner.class)
public class Tests {
@Mock
private ISomething mockedSomething;
@Test
public void test1() {
// Is the value of mockedSomething here
}
@Test
public void test2() {
// Is a new value of mockedSomething here
}
}
有人能指出有什么区别吗?什么时候我想用一个代替另一个?
【问题讨论】:
标签: java mocking mockito powermockito