Q16 of 40 · Karate

How do you integrate Karate with JUnit 5? What changes in CI?

KarateMidkaratejunit5ci-cdmavenrunner

Short answer

Short answer: Use the @Karate.Test annotation on a class with a @Test method that calls Runner.path().parallel(n).execute(). JUnit 5 discovers it normally via the JUnit Platform. In CI, the maven-surefire-plugin with the JUnit Platform provider runs it, and XML results go to target/karate-reports — not the standard surefire-reports folder.

Detail

Two integration styles:

Style 1 — Simple single feature (useful for running one feature from IDE):

@Karate.Test
Karate testUserFeature() {
    return Karate.run("classpath:features/users/get-user.feature");
}

Style 2 — Full parallel suite (for CI):

class SuiteRunner {
    @Test
    void runAll() {
        Results results = Runner.path("classpath:features")
            .parallel(4);
        assertThat(results.getFailCount()).isZero();
    }
}

Maven setup (pom.xml):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.2.5</version>
    <configuration>
        <includes>
            <include>**/*Runner.java</include>
        </includes>
    </configuration>
</plugin>

CI changes:

  • Reports: target/karate-reports/karate-summary.html — not surefire-reports
  • Publish with HTML Publisher plugin (Jenkins) or upload-artifact (GitHub Actions)
  • JUnit XML: enable with .outputJunitXml(true) on the Runner — needed for CI test result parsing

// EXAMPLE

KarateSuiteRunner.java

import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

// File must match the surefire include pattern (e.g., ends with Runner)
class KarateSuiteRunner {

    @Test
    void runAllApiTests() {
        Results results = Runner
            .path("classpath:features")       // discovers all .feature files
            .tags("~@wip", "~@manual")        // skip WIP and manual-only tags
            .outputJunitXml(true)             // target/karate-reports/*.xml
            .outputCucumberJson(true)
            .parallel(Runtime.getRuntime().availableProcessors());

        assertThat(results.getFailCount())
            .as(results.getErrorMessages())
            .isZero();
    }
}

// GitHub Actions — publish Karate HTML report
// - uses: actions/upload-artifact@v4
//   with:
//     name: karate-report
//     path: target/karate-reports/

// WHAT INTERVIEWERS LOOK FOR

Two integration styles (single feature vs parallel suite), the maven-surefire include pattern, JUnit XML output for CI, and the report location (karate-reports, not surefire-reports). These are concrete operational details that reveal hands-on CI experience.

// COMMON PITFALL

Expecting Karate reports to appear in target/surefire-reports — they don't. Karate writes to target/karate-reports. CI pipelines that look in the wrong folder appear to have no test results even when all tests passed.