1、创建springboot相关工程
2、引入相关依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
3、创建测试包及类
使用注解
@SpringBootTest
@RunWith(SpringRunner.class)
publicclassProductInfoRepositpryTest{
@Autowired
ProductInfoRepositoryinfoRepositpry;
@Test
publicvoidfindOne(){
StringproductId="1";
ProductInfoproductInfo=newProductInfo();
Optional<ProductInfo>infoOptional=infoRepositpry.findById(productId);
if(infoOptional.isPresent()){
productInfo=infoOptional.get();
}
Assert.assertNotNull(productInfo);
}