Kotlin Multiplatform parameterized tests with Burst

Unit tests are great. They give us confidence to build and change our software.

Sometimes I want to write a test once and run it for multiple algorithms, inputs, or environments. It’s been possible to do this with JUnit for a long time:

But I’ve missed this feature in my Kotlin Multiplatform projects!

So today we’re announcing Burst 2.0, a Gradle plug-in that adds support for parameterized tests to Kotlin/Multiplatform projects. It is a spiritual successor to Square’s Burst library, so we’re using ‘2.0’ for our first release.

To use Burst:

  1. Add the Burst plugin to your project’s Gradle build
  2. Add @Burst to your test class
  3. Add parameters to the constructor, test functions, or both.
@Burst
class WebServerTest(
  val protocol: Protocol = burstValues(Http1(), Http2(), Http3()),
) {
  @Test
  fun getRequest() {
    dispatchGetRequest(protocol)
  }

  @Test
  fun postRequest() {
    dispatchPostRequest(protocol)
  }
}

Run the test suite to see results for each combination of parameters:

Use burstValues() to specify each parameter’s tested values. The first argument is used when you test in the IDE.

It’s not necessary to use burstValues() for enums and booleans: Burst will test all possible values. Specify a default value to use it when testing in the IDE.

It’s possible to create a lot of tests this way. Burst runs every combination of test parameters, on every Kotlin/Multiplatform target.

Get Burst on GitHub.