我使用spring-boot-1.5.10.RELEASE和spring-boot-starter-test进行单元测试,它内置了JUnit-1.4。我想在我的项目中使用JUnit-1.5。我浏览了互联网上的大部分搜索结果链接到spring-boot-2.0.我们不能使用JUnit-5和sprint-boot-1.5.X?
GitHub链接或提示将是非常可观的。
发布于 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相关的依赖项。
<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版本添加它们,或者您可以声明版本。
<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>发布于 2018-12-03 22:22:28
如果您有一个Spring Framework大于5.0的项目,或者一个SpringBoot大于2.0版本的项目,那么您就无法在spring库的源代码中找到SpringExtension类。这个扩展提供了使用Spring运行JUnit5集成测试的能力。
要解决这个问题,需要添加Sam的依赖项:
<dependency>
<groupId>com.github.sbrannen</groupId>
<artifactId>spring-test-junit5</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>此外,还需要在pom文件的存储库块中添加jitpack:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>https://stackoverflow.com/questions/53472729
复制相似问题