Risalat Zaman
Risalat Zaman

Reputation: 1337

Cannot run explicitly tagged test only in Kotest

I have a spring boot project which uses kotlin version 1.7.0. My pom looks something like below.

   <properties>
    <kotlin.version>1.7.0</kotlin.version>
    ...
   </<properties>
   <dependencies>
    <dependency>
        <groupId>io.kotest</groupId>
        <artifactId>kotest-runner-junit5-jvm</artifactId>
        <version>5.3.1</version>
        <scope>test</scope>
    </dependency>
      ...
   </dependencies>
     .....
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>3.0.0-M6</version>
            <configuration>
                <forkCount>1</forkCount>
                <reuseForks>true</reuseForks>
                <runOrder>alphabetical</runOrder>
                <useUnlimitedThreads>true</useUnlimitedThreads>
                <redirectTestOutputToFile>true</redirectTestOutputToFile>
                <argLine>-Xmx2560m -Dspring.test.context.cache.maxSize=24 --enable-preview ${argLine}</argLine>
            </configuration>
    </plugin>

My kotest test class looks like below,

@Tags("CustomTest")
class CustomTestClass : FunSpec({
   blah blah
})

When I try to run only tests tagged with CustomTest using below command

./mvnw test -Dkotest.tags="CustomTest"

It runs all the tests in the project anyways. Could anyone help me debug this problem?

I followed this approach from the kotest docs

https://kotest.io/docs/5.3/framework/tags.html

Upvotes: 3

Views: 177

Answers (1)

Oliver O.
Oliver O.

Reputation: 721

The reason is probably that the system property in the command line (-Dkotest.tags="CustomTest") is not propagated to the forked JVM used for testing.

The documentation describes a way to inherit those properties from the parent JVM:

To inherit the systemProperties collection from the parent configuration, you will need to specify combine.children="append" on the systemProperties node in the child pom:

  <systemProperties combine.children="append">
      <property>
         [...]
      </property>
   </systemProperties>

Upvotes: 0

Related Questions