Thread
#multiplatform
    pablisco

    pablisco

    3 years ago
    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
    russhwolf

    russhwolf

    3 years ago
    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.
    class Case1 : ParameterizedTest(1)
    class Case2 : ParameterizedTest(2)
    
    open class ParameterizedTest(val parameter: Int) {
      @Test fun foo() { /* ... */ }
    }
    pablisco

    pablisco

    3 years ago
    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 😅
    russhwolf

    russhwolf

    3 years ago
    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

    robstoll

    3 years ago
    you could use Atrium in case your platforms are one of Android/JS/JVM:https://github.com/robstoll/atrium#data-driven-testing
    pablisco

    pablisco

    3 years ago
    That looks interesting, although it’s the same results as using a loop over a map of values really 😅
    r

    robstoll

    3 years ago
    almost, just error reporting will include all results
    pablisco

    pablisco

    3 years ago
    true that 🙂