2.1单元测试入门
步骤
@SpringBootTest
@RunWith(SpringRunner.class)
public class DeviceModelLableServiceTest {
@Mock
private DeviceModelLabelRespository repository;
@Mock
private DeviceInstanceRepository deviceInstanceRepository;
@InjectMocks
private DeviceModelLabelServiceImpl service;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void insertDeviceModelLable() {
//模拟dao
DeviceModelLabel deviceModelLable = new DeviceModelLabel();
when(repository.findByDeviceModelId("deviceModelId")).thenReturn(lables);
...
}
}常用mockito方法
常用断言
参考文档
Last updated