Skip to content

Repository files navigation

JUnit 6 Kotlin Workshop

Kotlin Java Gradle JUnit License

A practical workshop with runnable examples of JUnit 6 features in Kotlin/JVM.

Related projects:

⭐ 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.

Table of contents

Back to top

Who is this for?

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

Back to top

Quick start

git clone https://github.com/a-oleynik/junit-kotlin-workshop.git
cd junit-kotlin-workshop

Run the tests on Linux, macOS, or Git Bash:

./gradlew clean test

Run the tests on Windows Command Prompt or PowerShell:

gradlew.bat clean test

The Gradle Wrapper downloads and uses the required Gradle version automatically.

Back to top

Prerequisites

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

Back to top

Versions

Component Version
Kotlin 2.4.0
JUnit 6.1.2
Java toolchain 21
Gradle Wrapper 9.6.0

Back to top

Available examples

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

Back to top

Start here

The examples can be explored in this order:

  1. AssertTest — learn the basic JUnit assertions.
  2. FixturesTest — observe the test lifecycle.
  3. ExceptionTest — verify expected exceptions.
  4. DisabledTest — disable individual tests or a complete test class.
  5. TimeoutTest — apply time limits to test execution.

Back to top

Command examples

The examples below use the Gradle Wrapper. On Windows Command Prompt or PowerShell, replace ./gradlew with gradlew.bat.

Run all tests

./gradlew clean test

Run a single test class

./gradlew test --tests "*AssertTest"

Run a single test method

./gradlew test --tests "*AssertTest.assertEquals verifies multiplication result"

Run multiple test classes

./gradlew test --tests "*AssertTest" --tests "*ExceptionTest"

Compile and run all verification tasks

./gradlew clean build

Build without running tests

./gradlew build -x test

Run tests with additional diagnostic output

./gradlew test --info

Back to top

Test report

The test task generates a Gradle HTML report:

build/reports/tests/test/index.html

Back to top

Project structure

.
├── 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

Back to top

Useful links

Back to top

License

This project is licensed under the Apache License 2.0. See LICENSE for details.

Back to top

About

A practical JUnit 6 workshop for Kotlin/JVM with Gradle, examples, and GitHub Actions

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages