https://kotlinlang.org logo
Title
r

reactormonk

07/05/2022, 2:43 PM
How do I write tests? Do you use https://kotlinlang.org/api/latest/kotlin.test/ ? There's no doc linked form there? 🤔
a

Alan B

07/05/2022, 2:57 PM
https://kotest.io is popular. The author @sam is a mod here.
1
👋🏻 1
h

hfhbd

07/05/2022, 3:05 PM
Or normal annotated tests (with uses junit on the jvm):
class Testing {
  @kotlin.test.Test
  fun testing() {
    kotlin.test.assertEquals(1, 1)
  }
}
But yes, the docs should contain a sample 😄
r

reactormonk

07/05/2022, 3:08 PM
What do I need to add in terms of dependency for
import kotlin.test.*
to work?
h

hfhbd

07/05/2022, 3:08 PM
implementation(kotlin("test")) in commonTest or testImplementation(kotlin("test-junit")) on jvm only projects
k

Klitos Kyriacou

07/05/2022, 5:17 PM
This is a helpful guide, albeit a bit dated: https://resources.jetbrains.com/storage/products/kotlinconf2018/slides/4_Best%20Practices%20for%20Unit%20Testing%20in%20Kotlin.pdf My current personal choices are: • Framework: JUnit 5. Because it seems more mature than kotlin.test (for example, unless I'm mistaken, kotlin.test doesn't have parameterized tests yet) • Mocking: MockK (when used in Kotlin, it's nicer than Mockito) • Assertions: Kotest (although I may be persuaded by AssertK) • Property-based testing: jqwik-kotlin