Java SpringBoot2.1.0有JUnit5依赖项,但是如何摆脱它呢?
我刚刚将我的项目升级为使用SpringBoot2.1.0(在2.0.x之前) 我有以下警告:Java SpringBoot2.1.0有JUnit5依赖项,但是如何摆脱它呢?,java,spring-boot,spring-boot-test,Java,Spring Boot,Spring Boot Test,我刚刚将我的项目升级为使用SpringBoot2.1.0(在2.0.x之前) 我有以下警告: [WARNING] Cannot find annotation method 'value()' in type 'org.junit.jupiter.api.extension.ExtendWith': class file for org.junit.jupiter.api.extension.ExtendWith not found 我可以添加dependency org.junit.jupi
[WARNING] Cannot find annotation method 'value()' in type 'org.junit.jupiter.api.extension.ExtendWith': class file for org.junit.jupiter.api.extension.ExtendWith not found
我可以添加dependency org.junit.jupiter/junit-jupiter api来解决这个警告,但我觉得这是一个“黑客”
我不想看到这种警告(尤其是我的项目将警告视为错误),我也不想用不必要的依赖性污染我的项目
我正在使用Maven,但我可以看到有人对Gradle也有同样的问题
如果将
org.junit.jupiter:junit-jupiter-api
依赖项添加到项目中,警告将消失。
它应该不会有什么坏处,因为它只是API jar,并且只在测试范围内。如果您使用
@springbootest
设置类=
:
@SpringBootTest(classes = {
MyAutoConfiguration.class,
MyAutoConfigurationIntegrationTest.TestContextConfiguration.class
})
答案在报告中提到:
可以在运行Spring Boot的测试类上指定的注释
基于测试。除此之外,还提供以下功能:
常规Spring TestContext框架:
当没有特定的上下文加载器时,使用SpringBootContextLoader作为默认上下文加载器
@已定义ContextConfiguration(加载器=…)
自动搜索
对于未使用嵌套@Configuration时的@SpringBootConfiguration,
并且没有指定显式类
您可以使用不依赖Junit5的@ExtendsWith
:
@RunWith(SpringRunner.class)
@ContextConfiguration(loader = SpringBootContextLoader.class,
classes = {
MyAutoConfiguration.class,
MyAutoConfigurationIntegrationTest.TestContextConfiguration.class
})
您可以将POM文件添加到问题中吗?您使用的是maven/gradle/…?maven,我只更改了spring boot版本。|您希望看到“有效的POM”还是仅用于项目?(这将是困难的,因为版本是由Spring和我的父POM管理)如果您正在升级Spring Bug jar版本,那么我认为您应该考虑升级依赖关系的版本以及需要保持向后兼容性的地方。从长远来看,这将有所帮助。问题是,例如
@DataJpaTest
或@springbootest
注释是用@ExtendWith
注释的,这是JUnit 5的一部分,因此,即使不使用JUnit 5 API,您似乎也必须在类路径中使用它。