Setting Up Gradle, JUnit 5, and Selenium Jupiter for Java Test Automation

This tutorial explains how to prepare a Java development environment, create a Gradle project, configure JUnit 5 and Selenium Jupiter, write a basic Selenium WebDriver test, and run the test using Gradle Wrapper, providing all required tools and code examples.

FunTester
FunTester
FunTester
Setting Up Gradle, JUnit 5, and Selenium Jupiter for Java Test Automation

Selenium is a suite of tools for browser automation, primarily used for testing web applications. One of its components, Selenium WebDriver, provides client libraries, a JSON‑wire protocol for communicating with browser drivers, and supports most major programming languages and operating systems.

Test preparation

First, install a Java JDK (OpenJDK is recommended) and Gradle, then choose a Java IDE such as IntelliJ IDEA Community or Professional, and have Git available.

Ensure the following tools are installed before you start:

Java JDK – latest version

Gradle – version 5.6 or newer

IntelliJ IDEA

Chrome browser – for running Selenium tests

Terminal – with basic Unix command support

Git – for source‑code version control

From scratch

To create an empty Gradle project, open a terminal and run:

mkdir demo
cd demo
gradle init --type basic --dsl groovy

The generated project is a bare‑bones DIY project without plugins or dependencies. It includes a redundant settings.gradle file that can be removed:

rm settings.gradle

Java and JUnit 5

Add the following to build.gradle to configure a basic Java project with JUnit 5:

plugins {
    id 'java'
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation('org.junit.jupiter:junit-jupiter:5.5.1')
}

test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
    }
}

This DSL configures the Gradle Java plugin, uses Maven Central to resolve the declared dependencies, and sets JUnit 5 as the test implementation. You can verify the configuration by running a Gradle build:

./gradlew build
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed

The ./gradlew command runs the Gradle Wrapper, so a global Gradle installation is not required.

JUnit Jupiter

To simplify Selenium WebDriver configuration, add the Selenium Jupiter extension (a JUnit 5 extension) to the dependencies list in build.gradle:

dependencies {
    testCompile('io.github.bonigarcia:selenium-jupiter:3.3.0')
}

Selenium Jupiter provides integration with Selenium and Appium, supports local and remote browsers, Docker‑based browsers, and Selenide configuration. Internally it uses WebDriverManager to handle browser driver binaries.

Note: To view all project dependencies (including transitive ones), run ./gradlew dependencies.

Directory and project files

The project initially has no Java source files. Create the test directory and a first test file with:

mkdir -p src/test/java/demo/selenium/todomvc
touch src/test/java/demo/selenium/todomvc/SeleniumTest.java

The SeleniumTest.java file contains a minimal test that confirms the project is set up correctly. It uses the Selenium Jupiter‑provided JUnit 5 extension and contains a single test method without assertions:

package pl.codeleak.demos.selenium.todomvc;

import io.github.bonigarcia.seljup.SeleniumExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.chrome.ChromeDriver;

@ExtendWith(SeleniumExtension.class)
class SeleniumTest {

    @Test
    void projectIsConfigured(ChromeDriver driver) {}
}

Run the test

Execute a Gradle build to confirm the test passes:

./gradlew build

demo.selenium.todomvc.SeleniumTest > projectIsConfigured() PASSED

BUILD SUCCESSFUL in 1s
3 actionable tasks: 2 executed, 1 up-to-date

Disclaimer: This article was originally published on the WeChat public account “FunTester”. Re‑publication is prohibited except by Tencent Cloud.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaGradleSeleniumJUnit 5Selenium Jupiter
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.