user13689608
user13689608

Reputation:

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

Upvotes: 1

Views: 842

Answers (2)

user13689608
user13689608

Reputation:

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>

Upvotes: 1

Peter Thomas
Peter Thomas

Reputation: 58128

First I tried this and it worked:

mvn test -Dtest=EmployeeKarateTests

But yes mvn test doesn't work. But it does when you comment out the <plugins> piece in the pom.xml.

I leave it to you to figure out the magic combination of library dependencies (spring boot test, junit 5 / jupiter, and maven surefire) that will work :)

Upvotes: 0

Related Questions