# Java browser test setup

> Configure TestNG or JUnit browser tests with Maven Surefire or Gradle, and prepare your JDK and offline build for KwikQA validation.

KwikQA reads Maven and Gradle test reports. To qualify for repair and validation, every failing test in the group must reach Selenium, Selenide, Playwright for Java, or Appium through its source, helpers, or page objects. Unit tests and tests whose browser use cannot be confirmed still support diagnosis.

## Prepare the JDK and build

Use macOS or Linux for validation. On Windows, you can still diagnose an existing Maven or Gradle report. Install the JDK and set `JAVA_HOME` to its absolute home directory, the one that contains `bin/java`. The examples below use Java 21.

Initialize your project's wrapper and run its tests once on the machine that will validate repairs. `--version` unpacks the wrapper distribution. A normal build also caches the plugins and dependencies KwikQA needs when it reruns tests offline.

```
./mvnw --version
./mvnw test
```

```
./gradlew --version
./gradlew test integrationTest
```

Keep the unpacked distribution under `MAVEN_USER_HOME` or `GRADLE_USER_HOME` when set, or under `~/.m2` or `~/.gradle`. Without a wrapper, install `mvn` or `gradle` on `PATH`. Set up the browser, driver, and app your tests use before running validation.

## Maven with TestNG

Put the TestNG `XMLReporter` listener under Surefire's `configuration`. The native TestNG report retains individual retry attempts and configuration method failures. This example writes native TestNG XML to `test-output` and Surefire JUnit XML to `target/surefire-reports`.

```
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>example.checkout</groupId>
  <artifactId>checkout-browser-tests</artifactId>
  <version>1.0.0</version>
  <properties>
    <maven.compiler.release>21</maven.compiler.release>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>7.12.0</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>4.51.0</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.16.0</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
          <properties>
            <property>
              <name>listener</name>
              <value>org.testng.reporters.XMLReporter</value>
            </property>
          </properties>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
```

```
./mvnw test
npx kwikqa analyze --report test-output/testng-results.xml --html
```

For JUnit on Maven, keep your JUnit dependencies and omit the TestNG listener. Use `--report target/surefire-reports` for Surefire JUnit XML, or `--report target/failsafe-reports` for Failsafe. For a TestNG report in another directory, point directly at its `testng-results.xml`.

## Gradle with JUnit, fixtures, and retries

Use one of these build files. Put browser specs in `src/integrationTest/java` and shared fixture code in `src/testFixtures/java`. The separate `integrationTest` task writes JUnit XML to `build/test-results/integrationTest`. KwikQA reads the test-retry plugin's retry results.

### Kotlin DSL

```
// build.gradle.kts
plugins {
  java
  `java-test-fixtures`
  id("org.gradle.test-retry") version "1.6.6"
}

repositories { mavenCentral() }

java {
  toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}

dependencies {
  testFixturesApi("org.seleniumhq.selenium:selenium-java:4.51.0")
}

testing {
  suites {
    named<JvmTestSuite>("test") {
      useJUnitJupiter("6.1.3")
    }
    register<JvmTestSuite>("integrationTest") {
      useJUnitJupiter("6.1.3")
      dependencies {
        implementation(project())
        implementation(testFixtures(project()))
      }
    }
  }
}

tasks.withType<Test>().configureEach {
  retry { maxRetries.set(1) }
}
```

### Groovy DSL

```
// build.gradle
plugins {
  id 'java'
  id 'java-test-fixtures'
  id 'org.gradle.test-retry' version '1.6.6'
}

repositories { mavenCentral() }

java {
  toolchain.languageVersion = JavaLanguageVersion.of(21)
}

dependencies {
  testFixturesApi 'org.seleniumhq.selenium:selenium-java:4.51.0'
}

testing {
  suites {
    test {
      useJUnitJupiter('6.1.3')
    }
    integrationTest(JvmTestSuite) {
      useJUnitJupiter('6.1.3')
      dependencies {
        implementation project()
        implementation testFixtures(project())
      }
    }
  }
}

tasks.withType(Test).configureEach {
  retry { maxRetries = 1 }
}
```

```
./gradlew integrationTest
npx kwikqa analyze --report build/test-results/integrationTest --html
```

For Gradle's standard `test` task, use `build/test-results/test`. To keep parameters out of JUnit's test titles, put `junit.jupiter.params.displayname.default = {displayName}[{index}]` in `junit-platform.properties` on the test runtime classpath.

## Check the result

Run the KwikQA command after the test runner produces its report, including when tests fail. Add `--local` to see failure groups without signing in. Use the same `--report` path when running `kwikqa fix`. For an eligible failure, follow [your first repair](https://kwikqa.com/docs/first-repair/). The CLI's `--capture` flag is for the JavaScript browser runners. If you use KwikQA's Selenium Java evidence adapter, use the native TestNG or build JUnit report for repair validation.

See [Java validation troubleshooting](https://kwikqa.com/docs/troubleshooting/#java-python), [Surefire's TestNG configuration](https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html), and [Gradle's JVM Test Suite documentation](https://docs.gradle.org/current/userguide/jvm_test_suite_plugin.html).

---

Source: https://kwikqa.com/docs/frameworks/java/, updated 2026-11-27
