Tutorial: Test code using JUnit in JVM
Configuration guides: Maven | Gradle
A sample project demonstrating how to write tests in Kotlin for Java applications. This project shows the migration path from Java tests to Kotlin tests while testing Java source code.
- Java 17 or higher
Using Maven:
cd initial  # or cd complete
./mvnw testUsing Gradle:
cd initial  # or cd complete
./gradlew testThis repository contains two versions of the same project:
kotlin-junit-sample/
├── initial/          # Starting point with Java tests
│   ├── src/
│   │   ├── main/java/    # Java source code
│   │   └── test/java/    # JUnit tests in Java
│   ├── pom.xml           # Maven configuration
│   └── build.gradle.kts  # Gradle configuration
│
└── complete/         # Final version with Kotlin tests
    ├── src/
    │   ├── main/java/    # Same Java source code
    │   └── test/java/    # JUnit tests in Kotlin
    ├── pom.xml           # Maven with Kotlin support
    └── build.gradle.kts  # Gradle with Kotlin plugin
Both projects contain a simple Todo application with:
- TodoItem - A Java class representing a todo item with title, description, completion status, and timestamps
- TodoRepository - A Java repository class for managing todo items in memory
- initial/: Contains comprehensive JUnit 5 tests written in Java
- complete/: Same tests converted to Kotlin, demonstrating idiomatic Kotlin testing patterns
- Java: 17
- Kotlin: 2.2.20 (test code only in complete version)
- JUnit: 5.11.0
- Build Tools: Maven and Gradle (both supported)
- UI Library: Jexer 1.6.0 (terminal UI library)
