首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Spring-Boot1.5.10中升级JUnit-5?

如何在Spring-Boot1.5.10中升级JUnit-5?
EN

Stack Overflow用户
提问于 2018-11-25 22:40:23
回答 2查看 1.7K关注 0票数 2

我使用spring-boot-1.5.10.RELEASEspring-boot-starter-test进行单元测试,它内置了JUnit-1.4。我想在我的项目中使用JUnit-1.5。我浏览了互联网上的大部分搜索结果链接到spring-boot-2.0.我们不能使用JUnit-5和sprint-boot-1.5.X?

GitHub链接或提示将是非常可观的。

EN

回答 2

Stack Overflow用户

发布于 2018-11-26 03:33:59

要迁移,可以使用Junit 5查看这个链接https://www.baeldung.com/junit-5-migration到依赖项,如果要使用https://www.petrikainulainen.net/programming/testing/junit-5-tutorial-running-unit-tests-with-maven/启动测试,应该排除与Junit 5相关的依赖项。

代码语言:javascript
复制
 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-test</artifactId>
     <version>1.5.1.RELEASE</version>
     <scope>test</scope>
     <exclusions>
          <exclusion> 
          <!-- declare the exclusion here -->
             <groupId>sample.junit</groupId>
             <artifactId>junit</artifactId>
          </exclusion>
     </exclusions> 
 </dependency>

并根据Junit 5版本添加它们,或者您可以声明版本。

代码语言:javascript
复制
 <properties>
    <junit-jupiter-engine.version>5.1.0</junit-jupiter-engine.version>
    <junit-vintage-engine.version>5.1.0</junit-vintage-engine.version>
    <junit-platform-launcher.version>1.1.0</junit-platform-launcher.version>
    <junit-platform-runner.version>1.1.0</junit-platform-runner.version>
 </properties>
票数 1
EN

Stack Overflow用户

发布于 2018-12-03 22:22:28

如果您有一个Spring Framework大于5.0的项目,或者一个SpringBoot大于2.0版本的项目,那么您就无法在spring库的源代码中找到SpringExtension类。这个扩展提供了使用Spring运行JUnit5集成测试的能力。

要解决这个问题,需要添加Sam的依赖项:

代码语言:javascript
复制
<dependency>
    <groupId>com.github.sbrannen</groupId>
    <artifactId>spring-test-junit5</artifactId>
    <version>1.2.0</version>
    <scope>test</scope>
</dependency>

此外,还需要在pom文件的存储库块中添加jitpack:

代码语言:javascript
复制
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53472729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档