https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
k

Kweku

04/08/2021, 11:57 PM
What Testing libraries/ frameworks is everyone using?
a

Arkadii Ivanov

04/09/2021, 7:40 AM
For multiplatform only this one: https://kotlinlang.org/api/latest/kotlin.test/
👍 3
👍🏿 2
t

tjohnn

04/09/2021, 8:33 AM
@Arkadii Ivanov any idea of multiplatform mocking library?
a

Arkadii Ivanov

04/09/2021, 8:37 AM
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

Oliver.O

04/09/2021, 8:46 AM
👍🏿 2
j

Jilles van Gurp

04/09/2021, 12:54 PM
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

Kris Wong

04/09/2021, 1:12 PM
there's mockk, but I try to use mocking sparingly
there are better patterns
v

Vitor Prado

04/09/2021, 1:24 PM
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

Arkadii Ivanov

04/09/2021, 1:58 PM
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

Javier

04/09/2021, 5:57 PM
mockk is Multiplatform I think
but I prefer kotest + fakes
r

russhwolf

04/09/2021, 6:27 PM
mockk has no native support, and I think only partial js support
k

Kweku

04/09/2021, 6:37 PM
@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

Kris Wong

04/09/2021, 6:39 PM
hmmm I thought i remember using mock w/ KMM, but I guess I just made that up in my head
m

marzelwidmer

04/10/2021, 1:21 PM
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

Oliver.O

04/10/2021, 3:20 PM
@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

marzelwidmer

04/11/2021, 3:06 PM
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

Kweku

04/11/2021, 3:58 PM
@marzelwidmer try asking in #kotest
👍 1
j

Javier

04/11/2021, 4:12 PM
if you run them from gradle they work are working?
m

marzelwidmer

04/11/2021, 4:58 PM
yes 😞
8 Views