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

相关推荐
后端小张19 小时前
基于飞算AI的图书管理系统设计与实现
spring boot
咖啡Beans20 小时前
使用OpenFeign实现微服务间通信
java·spring cloud
考虑考虑2 天前
Jpa使用union all
java·spring boot·后端
咖啡Beans2 天前
SpringCloud网关Gateway功能实现
java·spring cloud
阿杆2 天前
同事嫌参数校验太丑,我直接掏出了更优雅的 SpEL Validator
java·spring boot·后端
昵称为空C3 天前
SpringBoot3 http接口调用新方式RestClient + @HttpExchange像使用Feign一样调用
spring boot·后端
麦兜*3 天前
MongoDB Atlas 云数据库实战:从零搭建全球多节点集群
java·数据库·spring boot·mongodb·spring·spring cloud
麦兜*3 天前
MongoDB 在物联网(IoT)中的应用:海量时序数据处理方案
java·数据库·spring boot·物联网·mongodb·spring
汤姆yu3 天前
基于springboot的毕业旅游一站式定制系统
spring boot·后端·旅游
计算机毕业设计木哥3 天前
计算机毕设选题推荐:基于Java+SpringBoot物品租赁管理系统【源码+文档+调试】
java·vue.js·spring boot·mysql·spark·毕业设计·课程设计