0Pricing
Kotlin Academy · Lesson

Assertions

Verify behavior.

What is an Assertion?

An assertion checks that an actual value matches what you expect. If it fails, the test fails with a helpful message.

JUnit5 provides assertions in org.junit.jupiter.api.Assertions.

assertEquals

The most common assertion. Note the order: expected first, actual second.

import org.junit.jupiter.api.Assertions.assertEquals

fun main() {
    val sum = 2 + 3
    assertEquals(5, sum)
    println("passed")
}

All lessons in this course

  1. Writing Tests with JUnit5
  2. Assertions
  3. Mocking with MockK
  4. Coroutine Testing
← Back to Kotlin Academy