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

}

 

猜你喜欢

转载自blog.csdn.net/weixin_36276193/article/details/82468709
今日推荐