Unit testing 在模拟对象上使用Mockit.reset()
在@Before方法中为模拟对象使用Mockito.reset()是否正确,该模拟对象正在同一测试类中的多个测试方法中使用,如下所示Unit testing 在模拟对象上使用Mockit.reset(),unit-testing,junit,mockito,Unit Testing,Junit,Mockito,在@Before方法中为模拟对象使用Mockito.reset()是否正确,该模拟对象正在同一测试类中的多个测试方法中使用,如下所示 public class SampleTest { @Mock private CustomRepository customRepo; @Before public void setUp() { Mockito.reset(customRepo); } @Test public void test1(){ ..
public class SampleTest {
@Mock
private CustomRepository customRepo;
@Before
public void setUp() {
Mockito.reset(customRepo);
}
@Test
public void test1(){
......
given(customRepo.someMethod()).willReturn(Answer1);
......
}
@Test
public void test2(){
......
given(customRepo.someMethod()).willReturn(Answer2);
......
}
}
您不必重置模拟,因为JUnit/Mockito会为每个测试创建一个新的
SampleTest
实例和模拟对象