springboot单元测试

1、使用

1)配置

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

java 复制代码
<!--单元测试配置开始-->
        <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处理

java 复制代码
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)

2、常见错误

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

https://blog.csdn.net/siaok/article/details/131421575

https://blog.csdn.net/qq_33732195/article/details/128172428

Command line is toolong

https://blog.csdn.net/weixin_42222436/article/details/126343482

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

https://blog.csdn.net/int_1021099885/article/details/136871623

websocket整合场景建议参看

https://blog.csdn.net/Lopka/article/details/121308803

相关推荐
风象南17 小时前
SpringBoot 实现无痕调试注入器,线上问题定位的新利器
spring boot·后端
javachen__1 天前
Spring Boot配置error日志发送至企业微信
spring boot·后端·企业微信
seabirdssss1 天前
使用Spring Boot DevTools快速重启功能
java·spring boot·后端
喂完待续1 天前
【序列晋升】29 Spring Cloud Task 微服务架构下的轻量级任务调度框架
java·spring·spring cloud·云原生·架构·big data·序列晋升
java水泥工1 天前
校园管理系统|基于SpringBoot和Vue的校园管理系统(源码+数据库+文档)
数据库·vue.js·spring boot
海上生明月丿1 天前
微服务01
java·spring boot·微服务
叫我阿柒啊1 天前
从Java全栈到前端框架的全面实战:一次真实面试的深度解析
java·spring boot·缓存·微服务·消息队列·vue3·rest api
Linlichaoblms1 天前
Nginx性能调优:参数详解与压测对比
java·spring boot·nginx
计算机毕业设计指导1 天前
基于Spring Boot的幼儿园管理系统
spring boot·后端·信息可视化