Hi everyone, I’m looking for resources on how to w...
# getting-started
h
Hi everyone, I’m looking for resources on how to write tests (unit, integration, e2e), any recommendation? Thanks in advance
s
The same way you'd do it in Java (so when googling, you don't have to make the search query Kotlin specific). The only difference is that in Kotlin you can have spaces in your test test function names if you use ` which makes the output a bit prettier, so instead of naming a test function
Copy code
@Test fun testThisThing() {...}
you can name it
Copy code
@Test fun `test this thing`() {...}
I generally use • kotlin-test as assertion lib on top of TestNG or JUnit5 on the JVM (but if you write a multi-platform app you probably want to look into kotest ) The nice thing with kotlin-test assertions are (compared to an assertion lib from Java) that the compiler understands that a variable that passes
assertNotNull(..)
can be smart-cast to its non-null type and everything after
fail(..)
is dead code. • mockk intead of mockito for mocking
j
A small warning about tests named with ``some spaces``: this doesn't work for the JS targets. I had to rename all my common tests the day I supported the JS targets
h
thanks guys!