冲突org.springframework.boot.test.context.SpringBootTest;和 org.springframework.test.context.junit.jupiter.SpringExtension;

Conflict org.springframework.boot.test.context.SpringBootTest; and org.springframework.test.context.junit.jupiter.SpringExtension;

我正在开发 spring 引导应用程序。 在我的 build.gradle 中,我添加了依赖项:

compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'

在我的服务中使用 MockMultipartFile:

import org.springframework.mock.web.MockMultipartFile;
...
...
MultipartFile multipartFile = new MockMultipartFile("file",
        file.getName(), "image/jpeg", IOUtils.toByteArray(input));

但是现在在测试中class我有这个错误:

这是我的 build.gradle:

依赖项{

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
    
compile 'org.hibernate:hibernate-core:5.2.11.Final'
compile 'org.hibernate:hibernate-entitymanager:5.2.11.Final'
compile 'mysql:mysql-connector-java'
compile 'org.apache.commons:commons-dbcp2:2.0.1'


compile 'javax.xml.bind:jaxb-api:2.3.1'
compile 'com.sun.xml.bind:jaxb-core:2.3.0'
compile 'com.sun.xml.bind:jaxb-impl:2.3.1'
compile 'javax.activation:activation:1.1.1'

compileOnly('org.projectlombok:lombok')
annotationProcessor 'org.projectlombok:lombok'

testCompile 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
testCompile('org.mockito:mockito-junit-jupiter:2.23.0')

compile 'org.modelmapper:modelmapper:2.3.0'

compile 'com.google.firebase:firebase-admin:6.13.0'
compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'

}

您使用的是相当旧的版本 Spring 测试:

compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'

我假设 Spring 测试 3.1.1 还没有 JUnit JUpiter SpringExtension。将 spring-test 更新为 a more recent version or remove it from your build.gradle and let Spring Boot with the Spring Boot Starter Test manage spring-test 的依赖版本。

因此,您更新后的 dependencies 部分可能如下所示:

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'

// this is your testing swiss-army knife - take a look at its transitive dependency
testImplementation 'org.springframework.boot:spring-boot-starter-test'

implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
    
compile 'org.hibernate:hibernate-core:5.2.11.Final'
compile 'org.hibernate:hibernate-entitymanager:5.2.11.Final'
compile 'mysql:mysql-connector-java'
compile 'org.apache.commons:commons-dbcp2:2.0.1'


compile 'javax.xml.bind:jaxb-api:2.3.1'
compile 'com.sun.xml.bind:jaxb-core:2.3.0'
compile 'com.sun.xml.bind:jaxb-impl:2.3.1'
compile 'javax.activation:activation:1.1.1'

compileOnly('org.projectlombok:lombok')
annotationProcessor 'org.projectlombok:lombok'

// REMOVE (managed by Spring Boot Starter Test) testCompile 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
// REMOVE (managed by Spring Boot Starter Test) testCompile('org.mockito:mockito-junit-jupiter:2.23.0')

compile 'org.modelmapper:modelmapper:2.3.0'

compile 'com.google.firebase:firebase-admin:6.13.0'
// REMOVE compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'