javaspringspring-bootkarate

Karate framework fails to find tests in multi module Spring Framework


Im trying to run my Karate tests with SpringBootTest but I'm getting the following error :

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

The Karate Test

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());
    }
}

Hierarchy

.
├── 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

Master 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>

Any help would really be appreciated. &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp


Solution

  • The problem was using jupiter with SpringBoot. The following dependencies resolved my issue.

    <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>