2

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().

u.sanyo
  • 47
  • 1
  • 7
  • I also was struggling with this. It seems focusing works only with top level test cases. – frenchu Apr 18 '20 at 17:46
  • 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: https://pawelweselak.com/posts/kotlintest-adventures/ – frenchu Apr 18 '20 at 17:53
  • The kotest intellij plugin is very powerful these days, you could try that, it will do what you want. – sksamuel Sep 04 '20 at 05:58
  • I've tried today v4.3.2, but it executes still both. – u.sanyo Dec 29 '20 at 09:51
  • 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. – sksamuel Jan 03 '21 at 22:27

2 Answers2

2

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

sksamuel
  • 16,154
  • 8
  • 60
  • 108
  • 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. – Neel Kamath Jun 21 '20 at 08:59
0

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.