1

How can QuarkusTestResource be used in conjunction with Tag Annotation?

Example Test Routine

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@Tag("integration")
@QuarkusTestResource(DatabaseResource.class)
public class MyTest {

    @Test
    public void () {
        doTests...
    }

}

Maven Snippet:

    <quarkus-plugin.version>1.12.1.Final</quarkus-plugin.version>
    <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
    <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
    <quarkus.platform.version>1.12.1.Final</quarkus.platform.version>
    <surefire-plugin.version>2.22.1</surefire-plugin.version>
    <testscope>unit</testscope>
...
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${surefire-plugin.version}</version>
        <configuration>
          <groups>${testscope}</groups>
          <systemPropertyVariables>
            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
            <maven.home>${maven.home}</maven.home>
          </systemPropertyVariables>
        </configuration>
      </plugin>
...

Maven Command:

./mvnw clean test

Result: QuarkusTestResource are started even if no QuarkusTest is annotated with "unit", so it seems that Quarkus is not aware of the Tag Annotation?

Nadine
  • 11
  • 2

2 Answers2

1

Quarkus Test Resources are global which means it will run anyway, even if your class is annotated with a tag that shouldn't run.

To prevent this, try annotating your class with

@QuarkusTestResource(restrictToAnnotatedClass = true)

From the Quarkus' website

test resources are global, even if they are defined on a test class or custom profile, which means they will all be activated for all tests, even though we do remove duplicates. If you want to only enable a test resource on a single test class or test profile, you can use @QuarkusTestResource(restrictToAnnotatedClass = true).

Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89
0

What you are looking for is likely the tags methof of QuarkusTestProfile. See this part of the documentation

geoand
  • 60,071
  • 24
  • 172
  • 190