1. 程式人生 > >SpringBoot與Test

SpringBoot與Test

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);

}