0Pricing
Kotlin Academy · Lesson

Testing and Evolving DSLs Without Breaking Users

Design DSL APIs for stability and test them with readable assertion blocks.

Why DSL Testing Is Different

A DSL is a public API. Changes to it can break every call site in user code. Testing a DSL means verifying both the output it produces and the structure it enforces — including that invalid constructs remain compile errors.

Testing DSL Output

The simplest test: build an object using the DSL and assert on the rendered result or the internal state of the builder.

@Test
fun `div contains a paragraph`() {
    val result = html {
        body {
            div { p("Hi") }
        }
    }
    assertTrue(result.render().contains("<p>"))
}

All lessons in this course

  1. Lambda with Receiver: The DSL Foundation
  2. @DslMarker: Preventing Receiver Leakage
  3. Building a Type-Safe HTML/Config DSL
  4. Testing and Evolving DSLs Without Breaking Users
← Back to Kotlin Academy