Last updated on
Kotlin Notes
My notes on Kotlin and libraries associated with Kotlin. Notes in the public.
Concepts
TBD
New Function Types
- Extension functions
- Scoped functions
Inline value class
Zero cost value objects
// For JVM backends
@JvmInline
value class Password(private val s: String)
Trailing lambda function
val product = items.fold(1) { acc, e -> acc * e }
Libraries
mockk
kotest
Kotlin testing library alternative to JUnit. Testing Framework, Assertion Library and Property Testing.
Notes:
- Unlike JUnit, by default when tests are run, each class is instantiated and
each test is run. This means, for example,
mockk
instances aren’t reset between tests. - Different testing styles
// Annotation Spec (similar to JUnit)
class AnnotationSpecExample : AnnotationSpec() {
@BeforeEach
fun beforeTest() {
println("Before each test")
}
@Test
fun test1() {
1 shouldBe 1
}
@Test
fun test2() {
3 shouldBe 3
}
}