A practical workshop with runnable examples of JUnit 6 features in Kotlin/JVM.
Related projects:
- JUnit Workshop — the complete Java counterpart of this Kotlin workshop
- Selenium Example (JUnit 6 branch) — a real-world Java Selenium WebDriver framework built on JUnit 6
⭐ Found it useful? If this project helps you, please give it a star — it helps others discover the repository.
Note
This project is a work in progress and is being expanded incrementally. The README documents only the examples that are already available in the repository.
- Who is this for?
- Quick start
- Prerequisites
- Versions
- Available examples
- Start here
- Command examples
- Test report
- Project structure
- Useful links
- License
| Audience | What you will get |
|---|---|
| QA engineers new to JUnit 6 | Small runnable examples of core JUnit features |
| Kotlin developers | JUnit examples written with Kotlin/JVM syntax and idioms |
| Java developers learning Kotlin | Familiar JUnit concepts shown in Kotlin |
| Workshop facilitators | A project that can be expanded topic by topic |
git clone https://github.com/a-oleynik/junit-kotlin-workshop.git
cd junit-kotlin-workshopRun the tests on Linux, macOS, or Git Bash:
./gradlew clean testRun the tests on Windows Command Prompt or PowerShell:
gradlew.bat clean testThe Gradle Wrapper downloads and uses the required Gradle version automatically.
| Tool | Version | Notes |
|---|---|---|
| JDK | 21 | Used by the Kotlin JVM toolchain |
| Gradle | 9.6.0 | Provided by the included Gradle Wrapper |
| IDE | Any | IntelliJ IDEA is recommended |
| Component | Version |
|---|---|
| Kotlin | 2.4.0 |
| JUnit | 6.1.2 |
| Java toolchain | 21 |
| Gradle Wrapper | 9.6.0 |
| Feature | Test class |
|---|---|
Basic assertions: equality, booleans, nullability, identity, and fail |
AssertTest |
Disabling a test method or an entire test class with @Disabled |
DisabledTest |
Test lifecycle with @BeforeEach, @AfterEach, @BeforeAll, and @AfterAll |
FixturesTest |
Exception testing with assertThrows |
ExceptionTest |
Time limits with assertTimeout and @Timeout |
TimeoutTest |
The examples can be explored in this order:
AssertTest— learn the basic JUnit assertions.FixturesTest— observe the test lifecycle.ExceptionTest— verify expected exceptions.DisabledTest— disable individual tests or a complete test class.TimeoutTest— apply time limits to test execution.
The examples below use the Gradle Wrapper. On Windows Command Prompt or PowerShell, replace ./gradlew with gradlew.bat.
./gradlew clean test./gradlew test --tests "*AssertTest"./gradlew test --tests "*AssertTest.assertEquals verifies multiplication result"./gradlew test --tests "*AssertTest" --tests "*ExceptionTest"./gradlew clean build./gradlew build -x test./gradlew test --infoThe test task generates a Gradle HTML report:
build/reports/tests/test/index.html
.
├── gradle/wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── src/
│ ├── main/kotlin/com/oleynik/qa/workshop/kotlin/junit/
│ │ ├── model/ # Example production models
│ │ └── Utils.kt # Utility used by timeout examples
│ └── test/kotlin/com/oleynik/qa/workshop/kotlin/junit/
│ └── general/ # Assertions, fixtures, exceptions, disabled tests, and timeouts
├── build.gradle.kts
├── gradle.properties
├── gradlew
├── gradlew.bat
└── settings.gradle.kts
- JUnit Workshop — comprehensive JUnit examples in Java
- TestNG Workshop — companion TestNG examples for side-by-side comparison
- Selenium Example (JUnit 6 branch) — a real-world Selenium WebDriver framework built on JUnit 6
- JUnit 6 Released — Clean-Up, Modernization & Minimal Disruption
- JUnit 6 User Guide
- Kotlin documentation
- Gradle User Manual
- Gradle Wrapper
- Gradle Kotlin DSL Primer
- Testing JVM projects with Gradle
This project is licensed under the Apache License 2.0. See LICENSE for details.