1 回答
TA贡献1808条经验 获得超4个赞
您可以使用服务层模拟DAO 层@RunWith(MockitoJUnitRunner.class)
组件来进行单元测试。你不需要它。SpringRunner.class
@RunWith(MockitoJUnitRunner.class)
public class GatewayServiceImplTest {
@Mock
private GatewayRepository gatewayRepository;
@InjectMocks
private GatewayServiceImpl gatewayService;
@Test
public void create() {
val gateway = GatewayFactory.create(10);
when(gatewayRepository.save(gateway)).thenReturn(gateway);
gatewayService.create(gateway);
}
}
您可以用于@DataJpaTest与DAO 层进行集成测试
@RunWith(SpringRunner.class)
@DataJpaTest
public class GatewayRepositoryIntegrationTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private GatewayRepository gatewayRepository;
// write test cases here
}
添加回答
举报