On this page
JUnit 5 Testing Framework
Overview
Qualified supports writing tests for Kotlin using JUnit 5.
Basic Example
Solution
fun add(a: Int, b: Int) = a + b
Tests
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
@DisplayName("Testing Adder")
class AdderTests {
@Test
@DisplayName("add(1, 1) returns 2")
fun addTwo() {
assertEquals(2, add(1, 1), "1 + 1 should equal 2")
}
@Nested
@DisplayName("Negative Integers")
class Negatives {
@Test
@DisplayName("add(-1, -1) returns -2")
fun addTwoNegative() {
assertEquals(-2, add(-1, -1), "-1 + -1 should equal -2")
}
}
}
Assertion Libraries
Following assertion libraries can be used:
Learn More
You can learn more on the JUnit website.