springboot单元测试

1、使用

1)配置

修改启动类所在的pom.xml增加单元测试,版本号注意与项目保持一致

<!--单元测试配置开始-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>2.0.9</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito2</artifactId>
            <version>2.0.9</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--单元测试配置结束-->

2)写单元测试

单元测试的包名与启动类的要一致
在这里插入图片描述

3)websocket处理

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)

2、常见错误

1)、java.lang.IllegalStateException Unable to find a @SpringBootConfiguration代码报错

https://blog.youkuaiyun.com/siaok/article/details/131421575

https://blog.youkuaiyun.com/qq_33732195/article/details/128172428

Command line is toolong

在这里插入图片描述
https://blog.youkuaiyun.com/weixin_42222436/article/details/126343482
在这里插入图片描述

2)java.lang.IllegalStateException: Failed to load ApplicationContext

https://blog.youkuaiyun.com/int_1021099885/article/details/136871623
websocket整合场景建议参看
https://blog.youkuaiyun.com/Lopka/article/details/121308803

评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值