Can't run unit tests

I have a multiplaform project, I added junit5 to my gradle file and put a test file under jvmTest/kotlin.

When I try to run it I get:

Execution failed for task ‘:jvmTest’.
No tests found for given includes: [co.mycompany.tests.HelloTest.hello](filter.includeTestsMatching)

I found this thread, which suggested adding withJava(). I did that and got an error about a duplicate resource (log4j2.xml), but now I can’t get that error again! It’s back to the error above.

I have a simple test like this and I’m trying to run it by clicking in the gutter next to the function.

import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.assertEquals

class HelloTest {

    @Test fun hello() {
        println("Hello.")
        assertEquals(2, 1+1)
    }
}

Doh. Nevermind. This did it, in my build.gradle.kts:

tasks.named<Test>("jvmTest") {
    useJUnitPlatform()
}

Can you please explain why did it help, it worked for me too?

Just to add to the answer

As you can see the log says Execution failed for task ‘:jvmTest’.

hence

tasks.named<Test>("jvmTest") {
    useJUnitPlatform()
}

In my case, it was just :test

so I used

tasks.named<Test>("test") {
    useJUnitPlatform()
}