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

相关推荐
陌殇殇1 小时前
SpringBoot整合SpringCache缓存
spring boot·redis·缓存
小林学习编程4 小时前
Springboot + vue + uni-app小程序web端全套家具商场
前端·vue.js·spring boot
ladymorgana4 小时前
【Spring boot】tomcat Jetty Undertow对比,以及应用场景
spring boot·tomcat·jetty
IT_10244 小时前
Spring Boot项目开发实战销售管理系统——系统设计!
大数据·spring boot·后端
DCTANT5 小时前
【原创】国产化适配-全量迁移MySQL数据到OpenGauss数据库
java·数据库·spring boot·mysql·opengauss
Touper.6 小时前
SpringBoot -- 自动配置原理
java·spring boot·后端
喜欢敲代码的程序员7 小时前
SpringBoot+Mybatis+MySQL+Vue+ElementUI前后端分离版:项目搭建(一)
spring boot·mysql·elementui·vue·mybatis
华子w9089258598 小时前
基于 SpringBoot+Vue.js+ElementUI 的 “花开富贵“ 花园管理系统设计与实现7000字论文
vue.js·spring boot·elementui
小时候的阳光9 小时前
SpringBoot3 spring.factories 自动配置功能不生效?
spring boot·spring·失效·factories·imports
大只鹅10 小时前
Springboot3整合ehcache3缓存--XML配置和编程式配置
spring boot·缓存