Hi! I’ve been experimenting with a <small DSL for ...
# kotest
n
Hi! I’ve been experimenting with a small DSL for tabular data in Kotlin, mainly to make parameterized tests less verbose and a bit more expressive. For example, with Kotest:
Copy code
import de.nielsfalk.dataTables.Data
import io.kotest.core.spec.style.FreeSpec

class HelloSpockTest : FreeSpec({
    "length of Spock's and his friends' names" - {
        @Data("name"   , "expectedLength") Spock {
              "Spock"  ǀ 5
              "Kirk"   ǀ 4
              "Scotty" ǀ 6
        }.each {
            "${name}'s name has length $expectedLength" {
                assert(name.length == expectedLength)
            }
        }
    }
})
I’m a fan of the good old Spock Framework, especially its data tables & power asserts, and I’m trying to bring some of that expressiveness to Kotlin. I’d really appreciate feedback from Kotest users: • Do you like this style? • Would you consider using something like this in your projects? • Is there anything about it that feels awkward or surprising?
👍 1
v
As long as it is about JVM-only and not KMP, there is work-in-progress for a Kotlin frontend to Spock to be able to write Spock specifications in Kotlin, maybe you are interested in that too. 🙂 pshevche.github.io/spockk
❤️ 1
n
Wow I had no Idea about Spockk and I love it. I startet 7 month before Spockk but I got interrupted it for a longer period. So now compairing them, my way of tabular data is even less verbose than Spockk but has less features and no IDE-plugin, it can be used in multiplatform projects and outside of tests. So I think it still has value depending on preferences and requirements.
a
Personally I don't like Spock at all, including these data tables, because: • if I need a wider value, all formatting needs to change, and it's harder to see in Github what exactly changed • less type safety • for larger tables, difficult to see which table cell means what, easier to deal with named parameters in a data class
so
Copy code
listOf(
TestCase(name = "Kirk", expectedLength = 4)
(snip)
can you share what power asserting features you are missing in Kotest?
v
if I need a wider value, all formatting needs to chang
It does not need to, it just improves readability, but is not a necessity. Also, you don't need to use data tables at all, they are overall just syntax sugar for multiple data providers with fixed values.
less type safety
No, you have full type safety if you wish so, just declare the type as method parameter like for all data variables
a
I really like how Spock displays some differences
v
Also, this thread is neither for promoting nor bashing Spock. If you don't like it, don't use it, but please don't spread false-facts about it. nfa said he likes it and wants to have something similar in Kotlin, so I pointed him at Spockk
n
can you share what power asserting features you are missing in Kotest?
no I like the way the official kotlin compiler plugin does it ( copied from groovy wich was inspired by Spock ( first spock than general groovy assertion feature) ), I can use it in kotest. So I’m fine.