2

I've got the following configuration in my build.gradle.kts:

tasks.withType<Test>().configureEach {
    testLogging {
        events = setOf(PASSED, SKIPPED, FAILED)
    }
}

My Kotest tests are similar to these:

class MyTests : StringSpec({

    "should fail" {
        1 shouldBe 2
    }

    "should skip".config(enabled = false) {}

    "should pass" {
        1 shouldBe 1
    }
})

However when I run ./gradlew test --info, I can see in the output the first two tests reported as FAILED and SKIPPED accordingly, but the last one is not reported at all, while I'd expect it to be so as PASSED.

Am I doing something wrong or is it a missing feature?

Please find the complete example here.

dominikbrandon
  • 408
  • 4
  • 16
  • 1
    It works fine on my side. Can you give a more complete example to fully replicate the problem? A complete minimal example of your `build.gradle.kts` would be helpful. – u-ways Feb 24 '23 at 22:31
  • Yes, you're right. Sorry, I haven't spent enough time investigating the issue. I've just managed to find out that it only occurs when running the task with the `--info` option enabled. Still, it's strange to me that it behaves like that. Please find the full code here: https://github.com/dominikbrandon/kotest-passed-issue. – dominikbrandon Feb 26 '23 at 10:32

1 Answers1

3

The test result is being reported, you can see the output of tests completed:

3 tests completed, 1 failed, 1 skipped

However, what's happening, when you add the --info flag, you're scoping the logging to INFO, in which the event SUCCESS is not set to INFO.

To amend this, you can configure your Gradle test task to add PASSED to INFO events:

tasks.withType<Test>().configureEach {
    testLogging {
        with(setOf(PASSED, SKIPPED, FAILED)) {
            events = this
            info.events = this
        }
    }
    useJUnitPlatform()
}
u-ways
  • 6,136
  • 5
  • 31
  • 47
  • 1
    Thanks for your help! One thing worth adding - one may also want not to replace the whole assignment, but rather expand it, because when you replace it, then for example stdout is not printed. In this case, you can go for something like this: `info.events = info.events union events`. – dominikbrandon Feb 27 '23 at 19:56