第十三章、Spring Boot单元测试

18 篇文章 0 订阅
18 篇文章 0 订阅

课时六十三、spring boot 1.3单元测试

SpringJUnit支持,由此引入Spring-Test框架支持! 
@RunWith(SpringJUnit4ClassRunner.class)

指定我们SpringBoot工程的Application启动类
@SpringApplicationConfiguration(classes = App.class)

///由于是Web项目,Junit需要模拟ServletContext,因此我们需要给我们的测试类加上@WebAppConfiguration。
@WebAppConfiguration

参考:spring-boot-handlerInterceptor

课时六十四、Spring Boot 1.4+单元测试

 @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)//随机端口号:避免端口碰撞.
public class AppTest {
    
    @Autowired
    private HelloController helloController;
    
    @Test //单元测试方法.
    public void testHello(){
    //    Assert.assertEquals("hello", helloController.hello());
        helloController.hello();
        System.out.println("xzxxx"+helloController.hello());

    }
    
}
 

参考:spring-boot-handlerInterceptor

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值