第一章、模拟对象 用于创建给定类或接口的模拟对象,创建对象的另一种方式就是直接用@Mock/InjectMocks注解来创建模拟对象,第三章有介绍。 注意:无法mock final类和final方法,静态方法和静态对象,私有方法。 import java.util.List; import static org.mockito.Mockito.*; public class MockitoMockMethodExample { public void testMultipleMocks() { List<String> mockList1 = mock(List.class); List<String> mockList2 = mock(List.class); when(mockList1.size()).thenReturn(5); when(mockList2.size()).thenReturn(10); assert(mockList1.size() == 5); assert(mockList2.size() == 10); } }...
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with doReturn .when
Contact doReturn .when, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack