在@Before方法中对模拟对象使用Mockito.reset()是否正确,模拟对象在同一测试类中的测试方法中使用如下所示。
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);
......
}
}
答案 0 :(得分:1)
您不必重置模拟,因为JUnit / Mockito会为每个测试创建public static final URL ICON16 = HelperUi.class.getResource("/com/jsql/view/swing/resources/images/software/bug16.png");
public static final URL ICON32 = HelperUi.class.getResource("/com/jsql/view/swing/resources/images/software/bug32.png");
public static final URL ICON96 = HelperUi.class.getResource("/com/jsql/view/swing/resources/images/software/bug96.png");
List<Image> images = new ArrayList<>();
try {
images.add(ImageIO.read(HelperUi.ICON96));
images.add(ImageIO.read(HelperUi.ICON32));
images.add(ImageIO.read(HelperUi.ICON16));
} catch (IOException e) {
LOGGER.error(e, e);
}
// Define a small and large app icon
this.setIconImages(images);
的新实例和模拟对象。