# Automating Exhaustive Branch Coverage for Sealed Types in Kotlin

DevFeed: [Automating Exhaustive Branch Coverage for Sealed Types in Kotlin](<https://devfeed.tech/articles/automating-exhaustive-branch-coverage-for-sealed-types-in-kotlin-20458.md>)

Original publisher: [Read original article](<https://eng.wealthfront.com/2025/11/20/sealed-tests/>)

Author: Sean Amos

Published: 2025-11-20T16:33:33Z

Content type: article

Language: en

Sources: [Wealthfront](<https://devfeed.tech/sources/wealthfront.md>)

Topics: [Unit testing](<https://devfeed.tech/topics/unit-testing.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [sealed interface](<https://devfeed.tech/topics/sealed-interface.md>), [Programming Language Type Systems](<https://devfeed.tech/topics/programming-language-type-systems.md>), [exhaustive matching](<https://devfeed.tech/topics/exhaustive-matching.md>), [Code quality](<https://devfeed.tech/topics/code-quality.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [automation](<https://devfeed.tech/tags/automation.md>), [code-quality](<https://devfeed.tech/tags/code-quality.md>), [code-review](<https://devfeed.tech/tags/code-review.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [exhaustive](<https://devfeed.tech/tags/exhaustive.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [junit](<https://devfeed.tech/tags/junit.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [parameterized-tests](<https://devfeed.tech/tags/parameterized-tests.md>), [runner](<https://devfeed.tech/tags/runner.md>), [sealed-classes](<https://devfeed.tech/tags/sealed-classes.md>), [test-coverage](<https://devfeed.tech/tags/test-coverage.md>), [testing](<https://devfeed.tech/tags/testing.md>), [unit-testing](<https://devfeed.tech/tags/unit-testing.md>), [wealthfront-engineering](<https://devfeed.tech/tags/wealthfront-engineering.md>)

## AI overview

Kotlin's sealed types let the compiler enforce exhaustive handling in `when` expressions, but JUnit does not ensure that unit tests cover every subtype passed to a function. Parameterized tests still depend on authors to supply the cases, and code review can miss omissions. The excerpt introduces a custom "Exhaustive Test Runner" intended to ensure at least one test case for each subclass of a sealed type, including subtypes added later. The supplied text ends as the article begins describing how to build it, so it does not establish the runner's implementation or usage details.

## Source excerpt

We take code correctness and code quality seriously at Wealthfront. One of the most effective ways we ensure that our code is correct is through rigorous unit testing and strong typing. In Kotlin, sealed classes and sealed interfaces offer a powerful tool to model restricted class hierarchies. They provide strong guarantees about the types in... Read more