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

相关推荐
用户3521802454751 天前
当 Prompt 学会"热更新":Spring Boot × Nacos3 AI 实战
java·spring boot·ai编程
昵称为空C1 天前
手撸一个动态 SQL 执行引擎:不重启服务,在线增删改查任意数据库
spring boot·后端
霸道流氓气质2 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
于先生吖2 天前
SpringBoot对接大模型开发AI命理测算系统:八字排盘与AI解析接口源码全解
人工智能·spring boot·后端
Flittly2 天前
【AgentScope Java新手村系列】(10)实战-多Agent天气助手
java·spring boot·spring
慧一居士2 天前
Feign的GET请求如何传递对象参数?
java·spring cloud
星落zx3 天前
Spring Boot 多模型集成:优雅调用全球主流大模型
人工智能·spring boot·chatgpt
一杯奶茶¥3 天前
水果销售网站 CRM客户信息管理系统 超市管理系 酒店管理系统 健身房管理系统 在线音乐网站 校园招聘系统
java·vue.js·spring boot·mysql·spring·java项目
进阶的小名3 天前
Spring Boot SSE + Nginx 配置:解决 EventSource 不实时返回、连接超时、流式响应被缓冲问题
spring boot·后端·nginx