ktoml icon indicating copy to clipboard operation
ktoml copied to clipboard

Switch the testing framework to Kotest?

Open NightEule5 opened this issue 3 years ago • 6 comments

Currently kotlin.test is used for testing. Have you considered Kotest instead? Like Kotlin's test framework, it's built on JUnit on the JVM, but tests are written in a more idiomatic way. There's also an IntelliJ plugin that can display the tests being run in real time, rather than producing a report at the end.

Here's an example of one style it provides:

object ExampleTest : StringSpec({
    "Test string length should be 11" {
        test().shouldHaveLength(11)
    }
})

// ...

fun test() = "test string"

This is, in my opinion, way easier to read than:

class ExampleTest {
    @Test
    fun testStringLength() {
        assertEquals(
            test().length,
            11
        )
    }
}

// ...

fun test() = "test string"

Transitioning would take some effort, but I think it's worth considering. Thoughts?

NightEule5 avatar Mar 14 '22 09:03 NightEule5

Good idea, we can try it. But actually you should know, that several people in JetBrains do not like this framework :) Everyone is familiar with Junit wrappers and do not want to try something new. But we can try it.

Unfortunately I am busy right now with the support for Custom deserialisers and Inline (VALUE) classes, so won't be able to make it in the nearest future... :(

orchestr7 avatar Mar 15 '22 18:03 orchestr7

@bishiboosh @petertrr what do you think about kotest?

orchestr7 avatar Mar 15 '22 18:03 orchestr7

Good idea, we can try it. But actually you should know, that several people in JetBrains do not like this framework :)

@akuleshov7 I would be interested to know why some people in Jetbrains do not like the framework? :)

sksamuel avatar Mar 16 '22 02:03 sksamuel

I would be interested to know why some people in Jetbrains do not like the framework? :)

As do I. It's great

NightEule5 avatar Mar 16 '22 03:03 NightEule5

Unfortunately I am busy right now with the support for Custom deserialisers and Inline (VALUE) classes, so won't be able to make it in the nearest future... :(

Understandable :)

NightEule5 avatar Mar 16 '22 03:03 NightEule5

@bishiboosh @petertrr what do you think about kotest?

I haven't tried kotest myself just yet, but I've read about it. Indeed, API looks nice and more kotlin-idiomatic. I was a little bit concerned about multiplatform support and IDE support, though.

As they say in kotest docs, IDE support for multiplafrom is limited and tests can't be run from IDE directly (though, it usualy doesn't work with kotlin.test too :| ).

I think it's worth a shot, and their library for property-based testing can be useful for testing ktoml, where there are a lot of similar test scenarios for different input data.

petertrr avatar Mar 16 '22 07:03 petertrr