Is it possible to do Parameterised tests on Kotlin...
# multiplatform
p
Is it possible to do Parameterised tests on Kotlin Multiplatform? The testing documentation is very limited and looking at the source I can’t find anything there
🍿 1
r
I'm not aware of any multiplatform parameterized test framework, but you DIY a bit by defining your tests in a base class and passing parameters as constructor arguments in subclasses.
Copy code
class Case1 : ParameterizedTest(1)
class Case2 : ParameterizedTest(2)

open class ParameterizedTest(val parameter: Int) {
  @Test fun foo() { /* ... */ }
}
p
Yeah, I wonder if it would work with sealed classes or enums. it’s a bit overkill, but may work for now 🙂
My hope was also to not have to think about names for each case 😅
r
Yeah it's not perfect but it'll get the job done for the moment until a better solution comes along
I did something like this recently but my use case required the cases to be in different modules than the base class. Without that limitation a sealed class or enum makes a lot of sense.
r
you could use Atrium in case your platforms are one of Android/JS/JVM: https://github.com/robstoll/atrium#data-driven-testing
p
That looks interesting, although it’s the same results as using a loop over a map of values really 😅
r
almost, just error reporting will include all results
p
true that 🙂