我尝试使用 SpringBootTest 运行我的空手道测试,但出现以下错误:
org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'junit-vintage' failed to discover tests
org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name: com.user.EmployeeKarateTest
空手道测试
import com.user.config.AbstractTestDefinition;
import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class EmployeeKarateTest extends AbstractTestDefinition {
@Test
void testParallel() {
Results results = Runner.path("classpath:com/user/").tags("~@ignore").parallel(5);
assertEquals(0, results.getFailCount(), results.getErrorMessages());
}
}
层次结构
.
├── common
│ ├── pom.xml
│ └── src
│ └── main
│ └── resources
│ └── application.properties
├── karate
│ ├── karate.iml
│ ├── pom.xml
│ ├── src
│ ├── main
│ │ └── resources
│ │ └── karate-config.js
│ └── test
│ └── java
│ └── com
│ └── user
│ ├── config
│ │ ├── AbstractTestDefinition.java
│ │ └── KarateContextConfiguration.java
│ ├── DeleteEmployeeTest.feature
│ ├── EmployeeKarateTest.java
│ ├── GetEmployeeTest.feature
│ ├── PostEmployeeTest.feature
│ └── PutEmployeeTest.feature
├── local-server
│ ├── pom.xml
│ └── src
│ └── main
│ └── java
│ └── localServer
│ ├── controllers
│ │ ├── GreetingController.java
│ │ └── PersonController.java
│ ├── entities
│ │ └── Person.java
│ ├── services
│ │ └── PersonService.java
│ └── StartLocalServer.java
├── pom.xml
主控POM
<build>
<testResources>
<testResource>
<directory>src/test/java/com/user</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<excludes>
<exclude>com/user/*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
任何帮助将不胜感激。
首先我尝试了这个并且有效:
mvn test -Dtest=EmployeeKarateTests
但是,
mvn test
不起作用。但是当您注释掉 <plugins>
中的 pom.xml
部分时,它就会出现。
我将它留给您来找出可行的库依赖项(spring boot test、junit 5 / jupiter 和 maven Surefire)的神奇组合:)
问题在于将 jupiter 与 SpringBoot 一起使用。以下依赖项解决了我的问题。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<version>0.9.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit5</artifactId>
<version>0.9.6</version>
<scope>test</scope>
</dependency>
</dependencies>