Annotation Interface WithTestResource


@Target(TYPE) @Retention(RUNTIME) @Documented @Repeatable(List.class) public @interface WithTestResource
Used to define a test resource, which can affect various aspects of the application lifecycle.

As of Quarkus 3.16, the default behavior of the annotation (meaning that scope has not been set) is that test classes annotated with the same WithTestResource will not force a restart of Quarkus.

The equivalent behavior to QuarkusTestResource(restrictToAnnotatedClass = false) is to use WithTestResource(scope = TestResourceScope.GLOBAL), while the equivalent behavior to QuarkusTestResource(restrictToAnnotatedClass = true) is to use WithTestResource(scope = TestResourceScope.RESTRICTED_TO_CLASS),

WARNING: this annotation, introduced in 3.13, caused some issues so it was decided to undeprecate QuarkusTestResource and rework the behavior of this annotation. For now, we recommend not using it until we improve its behavior.

Note: When using the scope=TestResourceScope.RESTRICTED_TO_CLASS, each test that is annotated with @WithTestResource will result in the application being re-augmented and restarted (in a similar fashion as happens in dev-mode when a change is detected) in order to incorporate the settings configured by the annotation. If there are many instances of the annotation used throughout the testsuite, this could result in slow test execution.

All WithTestResource annotations in the test module are discovered (regardless of the test which contains the annotation) and their corresponding QuarkusTestResourceLifecycleManager started before any test is run.

Note that test resources are never restarted when running @Nested test classes.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
     
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
     
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
     
    boolean
    Whether this test resource is to be started in parallel (concurrently) along with others also marked as parallel
    Defines how Quarkus behaves with regard to the application of the resource to this test and the test-suite in general.
  • Element Details

    • initArgs

      ResourceArg[] initArgs
      Returns:
      The arguments to be passed to the QuarkusTestResourceLifecycleManager
      See Also:
      Default:
      {}
    • parallel

      boolean parallel
      Whether this test resource is to be started in parallel (concurrently) along with others also marked as parallel
      Default:
      false
    • scope

      Defines how Quarkus behaves with regard to the application of the resource to this test and the test-suite in general. The default is TestResourceScope.MATCHING_RESOURCES which means that if two tests are annotated with the same WithTestResource annotation, no restart will take place between tests.
      Default:
      MATCHING_RESOURCES