What Testing libraries/ frameworks is everyone usi...
# multiplatform
k
What Testing libraries/ frameworks is everyone using?
a
For multiplatform only this one: https://kotlinlang.org/api/latest/kotlin.test/
👍 3
👍🏿 2
t
@Arkadii Ivanov any idea of multiplatform mocking library?
a
AFAIK there is no such a library. Personally I stopped using mocking libraries in any project once I got used to testing without mocking. I use Fakes and Stubs. You can read more about it here: https://medium.com/@june.pravin/mocking-is-not-practical-use-fakes-e30cc6eaaf4e
💯 1
👍 5
👍🏿 2
o
👍🏿 2
j
We use kotest assertions but typically with either junit5 on jvm or kotlin.test (subset of the junit annotations). We don't use the kotest testing dsl. I kind of like the idea of it but it's a bit of a PITA to make work with intellij if you want to just run a single test (it runs everything).
👍🏿 2
k
there's mockk, but I try to use mocking sparingly
there are better patterns
v
I’m writing tests on jvm/android target only. spek + kluent (for assertions) + mockk (for mocking) + turbine (for coroutines-flow testing) Spek and Kotest has the same dsl for testing (rspec spectations style)
kotest has a builtin assertion lib.. but spek has a simple feature I really like: spek creates a
memoized
delegate for properties, it recreates the var for each test.
a
Running tests only on JVM is an option for sure. But please keep in mind that you may miss bugs as follows. This test fails only on JS:
Copy code
@Test
fun foo() {
    val original = Float.MAX_VALUE
    val bits = original.toRawBits()
    val result = Float.fromBits(bits)
    assertEquals(original, result)
}
Also there are differences due to K/N memory model, which can also be verified by tests. Etc.
💯 1
j
mockk is Multiplatform I think
but I prefer kotest + fakes
r
mockk has no native support, and I think only partial js support
k
@Oliver.O thanks I started with Kotest recently just wondering what else is there
👍 1
@Arkadii Ivanov yh I definitely need Native tests, native specific differences especially cos of the memory model is why i'm looking to increase my testing
k
hmmm I thought i remember using mock w/ KMM, but I guess I just made that up in my head
m
you guyes update also to junit5 the KMM I halso work with koin. or just kotest are fine? I was trying and stop it later again to create setup with jupitor
o
@Jilles van Gurp Have you ever tried the Kotest IntelliJ Plugin? I'm using it to run single tests from gutter icons or plugin's test explorer. Before trying the plugin, I was using conditional evaluation or Gradle's test filter (
includeTestsMatching
) to single out tests.
m
What I miss here …I try to add Kotest with version `4.4.3`… Nothing start….. 😞
Copy code
val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.2")

                implementation("io.kotest:kotest-framework-engine:${Versions.kotest}")
                implementation ("io.kotest:kotest-assertions-core:${Versions.kotest}")
                implementation ("io.kotest:kotest-property:${Versions.kotest}")
                implementation ("io.kotest:kotest-runner-junit5-jvm:${Versions.kotest}")
            }
        }
I have default
KMM
gradle setup from the wizard.
ok at least I get it running on Terminal with adding
Copy code
tasks {
    // Tests
    withType<Test> {
        useJUnitPlatform()
    }
}
k
@marzelwidmer try asking in #kotest
👍 1
j
if you run them from gradle they work are working?
m
yes 😞