mock测试
作者:互联网
添加依赖
<properties>
<mockito.version>2.23.0</mockito.version>
</properties>
<!--mockito-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
测试类
public class XxxServiceImplTest { @InjectMocks private SC001ServiceImpl sC001ServiceImpl; @Mock private LA_MF_AbnormalMapper laMfAbnormalMapper; @Mock private ScenicMapper scenicMapper; @Before public void init() throws Exception { MockitoAnnotations.initMocks(this); } @Test public void getInterpretDataTest(){ when(laMfAbnormalMapper.getAllAbnormalNumByYesterday(null)).thenReturn(allAbnormalNum); when(laMfAbnormalMapper.getAbnormalByDate("")).thenReturn(average); Result result = sC001ServiceImpl.getInterpretData(filter); Assert.assertNotNull(result.getData()); } @Test public void getAbnormalEventSTest(){ when(laMfAbnormalMapper.getAllAbnormalByScenicId(any())).thenReturn(num); Result t = sC001ServiceImpl.getAbnormalEventS(filter); Assert.assertNotNull(t.getData()); }
其他
@value解决
ReflectionTestUtils.setField(la_mf_003_drService,"prefixUrl","hehehhehelala");
标签:thenReturn,mockito,when,private,测试,laMfAbnormalMapper,public,mock 来源: https://www.cnblogs.com/yangzhongzhong/p/15321350.html