How to run a single test in a context using kotest/kotlintest
Asked Answered
D

3

6

I have the following test suite:

class FooTest : FunSpec() {
    init {
        context("a context") {
            test("first test") {
                true shouldBe false
            }

            test("f:second test") {
                true shouldBe true
            }
        }
    }
}

I try to execute it in IntelliJ Idea. Unfortunately it executes both test in the suite. It works well if I don't nest the test in context().

Disclaimer answered 11/3, 2020 at 9:52 Comment(5)
I also was struggling with this. It seems focusing works only with top level test cases.Catamnesis
What you can do is to try bang other test cases with exclamation mark "!". To make use of that install kotest/kotlintest IntelliJ plugin. And run tests using this plugin. If you are building your project with gradle switch to IntelliJ test runner. It can be done by editing IntelliJ settings under "Build, Execution, Deployment > Build Tools > Gradle". More on this in my blog post: pawelweselak.com/posts/kotlintest-adventuresCatamnesis
The kotest intellij plugin is very powerful these days, you could try that, it will do what you want.Chellean
I've tried today v4.3.2, but it executes still both.Disclaimer
If you click the run icon on line 3 (context) it will run context + the nested tests. If you click run on line 4 or line 8 it will run context + the test you clicked on. Focus does not work on nested tests as per the docs.Chellean
B
6

There is an IntelliJ plugin which provide features to run a single test and many more features.

Using this plugin, if you click the run/play icon on line 3 (context) it will run the context + the nested tests. If you click run on line 4 or line 8 it will run context + the test you clicked on. Focus does not work on nested tests as per the docs

Brookbrooke answered 25/4, 2020 at 21:22 Comment(1)
Has focusing tests in containers been left out because it's technically too difficult, or can we expect this in a future release? Because I can't use an IntelliJ plugin to run tests. Although I use IntelliJ, my program runs in a complex Docker setup, and IntelliJ's Docker plugin lacks the configurability to run it; which means I can't use things like gutter icons for testing.Jerkwater
B
0

You can from the command line using the kotest_filter_tests environment variable:

kotest_filter_tests='a context' ./gradlew test
Ballista answered 7/1 at 14:37 Comment(0)
E
-1

Take sure about which library are you working. On Koltin have io.kotest and io.kotlintest, both have the faces for test. In my case, usint io.koltintest the context is created just putting his name:

"my context"{
    should("test name")
}

In some style like StringSpec, in the context doesn't is accept.

Embrace answered 23/3, 2023 at 19:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.