import java.util.List; import org.junit.*; import org.mockito.*; public class ExampleTest { \t@Test \tpublic void testExampleMethod() { \t\tList<String> mockedList = Mockito.mock(List.class); \t\t \t\tMockito.when(mockedList.size()).thenReturn(5); \t\t \t\tint size = mockedList.size(); \t\t \t\tMockito.verify(mockedList, Mockito.times(1)).size(); \t\t \t\tAssert.assertEquals(5, size); \t} } <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>3.11.2</version> <scope>test</scope> </dependency>


上一篇:
下一篇:
切换中文