Skip to content

BehaviorSpec When blocks are not displayed correctly in Android Studio test tree #377

@waffiqaziz

Description

@waffiqaziz

Description:

When running Kotest BehaviorSpec tests in Android Studio, the test tree in the Run/Test Results panel does not correctly nest When conditions under their Given scopes.
Instead, all When conditions appear flat, and Then conditions are not shown as a hierarchical tree.

Example Code:

class MyFavoriteViewModelKotestTest : BehaviorSpec({
  Given("checks TV state before posting to watchlist") {
    When("the TV show is not in watchlist") {
      Then("it should call postWatchlist and emit success") {
        // test
      }
    }
    When("the TV show is already in watchlist") {
      Then("it should emit snackBarAlready with title") {
        // test
      }
    }
  }
})

Expected Behavior:

The test results should appear as a proper hierarchy:

Given: checks TV state before posting to watchlist
  When: the TV show is not in watchlist
    Then: it should call postWatchlist and emit success
  When: the TV show is already in watchlist
    Then: it should emit snackBarAlready with title

Actual Behavior:

Android Studio shows:

Given: checks TV state before posting to watchlist
  When: the TV show is not in watchlist
    Then: it should call postWatchlist and emit success
    Then: it should emit snackBarAlready with title

The second When is missing, and its Then is wrongly grouped under the first When.

Environment:

  • Kotest: 6.0.0
  • Kotest Android Studio Plugin: 6.0.101-2025.1
  • Android Studio: Android Studio Narwhal Feature Drop | 2025.1.2 AI-251.26094.121.2512.13840223 July 26, 2025
  • OS: Windows 10

Screenshots

Image

Screenshots from my actual code on android studio

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions