开发者社区> 问答> 正文

如何在Spring Boot项目中添加JUnit的Maven依赖?

如何在Spring Boot项目中添加JUnit的Maven依赖?

展开
收起
花开富贵111 2024-06-20 16:00:57 29 0
2 条回答
写回答
取消 提交回答
  • Spring Boot 2.x开始默认支持JUnit 5,下面就是添加的JUnit 5的依赖,没什么很特殊的,注意版本就好

    <dependencies>
        <dependency>
    <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>5.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    

    回答不易请采纳

    2024-06-21 09:51:24
    赞同 3 展开评论 打赏
  • 在Spring Boot项目中添加JUnit的Maven依赖,你需要在pom.xml文件中加入JUnit相关的依赖。

    由于Spring Boot默认已经包含了对JUnit的依赖,但如果你需要特定版本的JUnit(例如,JUnit 5),可以按照以下步骤操作:

    打开你的pom.xml文件。
    在标签内,添加JUnit 5的依赖。默认Spring Boot会自动管理版本,但如果你想指定特定版本,可以包含标签。 如果使用Spring Boot默认的JUnit版本(通常是JUnit 5):
    image.png

    2024-06-20 16:33:08
    赞同 1 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载