question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nesting `When` under `When` in `BehaviorSpec` results in silently ignored tests

See original GitHub issue

As illustrated in the sample project, doing something along the lines of:

class DemoTest : BehaviorSpec({

    Given("given") {
        When("top when") {
            When("bottom when") {
                Then("assertion") {
                    1 shouldBe 2
                }
            }
        }
    }
})

and the isolation mode set to IsolationMode.InstancePerLeaf results in all tests passing without execution.

If the isolation mode is left at the default, the outer When is ignored as not containing any tests/leafs, so also not great.

If I understand correctly, Whens are not supposed to be nested under Whens but it’s something that is very easy to miss when writing or reviewing code, and you end up with silently broken test code.

Is it possible to mitigate this in any way?

Which version of Kotest are you using

5.3.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sksamuelcommented, Jun 12, 2022

@Kantis I’ve taken the latest snapshot after merging this, and applied it to one of my projects, and tried the above snippet. The nested When is now correctly highlighted as invalid.

image

0reactions
Kantiscommented, Jun 12, 2022

Awesome! I must’ve done something wrong when building locally then 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Styles - Kotest
To use Kotest, create a class file that extends one of the test styles. ... Tests can be nested in one or more...
Read more >
Introduction to Kotest | Baeldung on Kotlin
Kotest is a multi-platform testing framework written in Kotlin. ... verify actual string is equal to the given string ignoring case result.
Read more >
qemu-devel (date) - GNU mailing lists
... [Qemu-devel] [PATCH for-2.5] blkdebug: silence warning under qtest, ... Add test for JSON nesting depth limit, Markus Armbruster, 07:48 ...
Read more >
Diff - gerrit - Google Git
Gerrit Daemon -WARNING: At the moment running this configuration results in a ... Unit tests To create run configurations for unit tests, run...
Read more >
Analyzing the NYC Subway Dataset - David J. Broadwater
Statistical Test Results. Performing the Mann-Whitney U test on this dataset produced a two-sided p-value of 0.049999825586979442 (just slightly below our ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found