Unit Testing in Kotlin is fun and tricky at the same time. We can benefit a lot from Kotlin’s powerful language features to write readable and concise unit tests. But to write idiomatic Kotlin test code in the first place, we have to pay attention to certain pitfalls and best practices.
This workshop covers the whole variety of testing in Kotlin. Starting from mock-based unit test over integration test to data-driven test and property-based tests. It presents battle-proved best practices based on the experience that I collected over the years of writing test code in Kotlin.
- You will learn how to write test code in Kotlin that is idiomatic, readable, concise, and produces reasonable failure messages.
- You will learn how to write unit test with Kotlin that handles the fixtures and data creation appropriately and uses modern and idiomatic libraries for mocking and asserting.
- You will write real-life integration tests in Kotlin that tests a complete vertical of your application while handling the database and remote services. You will also learn the benefits of parameterized tests.
- You will learn how to write data-driven tests and property-based tests in Kotlin.
- You will learn how you can use Kotlin’s features to write idiomatic and clean test code.
- You will learn universal testing best practices. Besides the Kotlin-specific recommendations, we cover a lot of universal best practices for writing readable and maintainable test code that can be applied to any language and ecosystem.
- Part 1: Mock-based Unit Tests
- Test Setup, Fixture Handling, and Lifecycle with JUnit5
- Naming and Grouping
- Overview over Test Libraries
- Kotest’s Matchers
- Mock Handling with Mockk
- Helper Functions for Concise and Clean Tests
- Part 2: Real-Life Integration Tests with Kotlin
- Integration Tests vs Unit Tests
- Testcontainers Integration
- Speeding up the Integration Tests
- The Power of Data Classes
- Parameterized Tests
- Part 3: Advanced Topics
- Kotest as an Alternative to JUnit5
- Testing Styles
- Data-Driven Tests
- Property-Based Testing
You will practice testing on a hands-on example that contains all challenges that you are also facing in a real-world project like databases and remote services. Our practical example is an HTTP backend service that is written in Spring Boot. Please note that even if you are not a backend developer, you can apply the patterns and best practices in this workshop to other domains like mobile development.
I will provide a GitHub repository that contains an HTTP backend service. In the workshop, we will write the test suite for this service. We will do this step by step - starting from unit tests, over integration tests to more advanced topics like data-driven tests or property-based testing.
The workshop contains three parts. Every part will start with a short presentation followed by one or multiple hands-on parts where the participants can practice the things they just learned. Afterward, we will discuss the possible solutions.
The workshop can be highly tailored to your needs. We can extend or reduce the content, focus on your specific issues and set the degree of interactivity as you prefer.