springboot单元测试配置

报错

Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available

在这里插入图片描述因为缺少websocket 。只需要配置 webEnviroment就可以了额

<!--jUnit包,,@RunWith得包-->
        <dependency
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
配置SpringBoot单元测试,可以按照以下步骤进行操作: 1. 引入依赖:在项目的pom.xml文件中添加Spring Boot测试的依赖项。可以使用以下代码片段将依赖项添加到pom.xml文件中: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> ``` 这些依赖项将提供执行单元测试所需的必要库和工具。 2. 添加注解:在需要进行测试的类上添加注解。使用`@RunWith`注解将测试运行器设置为SpringRunner,并使用`@SpringBootTest`注解指定要启动的Spring Boot应用程序的入口类。以下是一个示例: ```java import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(classes={YourApplication.class}) public class YourTestClass { // 测试方法 } ``` 在上述示例中,`YourApplication.class`应替换为你的Spring Boot应用程序的实际入口类。 3. 编写测试方法:在测试类中编写测试方法,并使用`@Test`注解标记这些方法作为测试方法。你可以在这些方法中编写针对不同功能的测试用例。 这样配置后,你可以使用IDE或者Maven等工具运行单元测试Spring Boot会自动加载应用程序上下文并执行测试方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [SpringBoot单元测试配置流程](https://blog.csdn.net/qq_38058674/article/details/123058717)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值