Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@TempDir not working when on a field on @QuarkusTest #13261

Open
xtaixe opened this issue Nov 12, 2020 · 7 comments
Open

@TempDir not working when on a field on @QuarkusTest #13261

xtaixe opened this issue Nov 12, 2020 · 7 comments
Assignees
Labels
area/testing kind/bug Something isn't working

Comments

@xtaixe
Copy link

xtaixe commented Nov 12, 2020

Describe the bug
Temp dir not being created and set when using @TempDir a field on @QuarkusTest. It works fine as a set up or test method parameter though.

Expected behavior
Temp dir is created and set on field.

Actual behavior
The field annotated with @TempDir is null

To Reproduce

@QuarkusTest
class MyTest {

    @TempDir
    Path tempDir;

    @Test
    public void defaultConfiguration() {
        System.out.println(tempDir); //Prints null
    }

}

Environment (please complete the following information):

  • Output of uname -a or ver: Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_6
  • Output of java -version:
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03)
OpenJDK 64-Bit Server VM GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03, mixed mode, sharing)
  • Quarkus version or git rev:1.8.1.Final (quickly tested with 1.9.2.Final and got the same result)
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
@xtaixe xtaixe added the kind/bug Something isn't working label Nov 12, 2020
@ghost ghost added the triage/needs-triage label Nov 12, 2020
@famod
Copy link
Member

famod commented Nov 16, 2020

/cc @geoand Is this a known limitation? I couldn't find anything in the docs or previous issues.

@geoand
Copy link
Contributor

geoand commented Nov 16, 2020

It's not a known limitation, but I guess it is to be expected.
Basically anything that gets injected into fields of the test outside of Quarkus' control, will not work - as QuarkusTest creates a different test object (because it needs to be handled on a different ClassLoader).

In this case, we can most likely add support for @TempDir in QuarkusTest.
Otherwise we can just tell people in the docs to use the method parameter variant.

@geoand geoand changed the title @TempDir not working when on a field on @QuarkusTest @TempDir not working when on a field on @QuarkusTest Nov 16, 2020
@Manfred73
Copy link

Manfred73 commented Oct 31, 2022

Running into this issue as well with a @QuarkusIntegrationTest. My application uses a configuration property with a directory location where it should look for files or write files to.

For my integration test I override this property with a different folder. I'd like to use the @TempDir annotation as an instance variable for this, but reading this, that won't work. I can't use the method parameter variant though since I need to override the getConfigOverrides method from the QuarkusTestProfile.

Having the ability to use something like @QuarkusTempDir would solve this I guess.

@malaskowski
Copy link

malaskowski commented Feb 3, 2023

I know this is not perfect, but here's a workaround (I tested it with 2.16.0.Final version):

@QuarkusTest
@TestProfile(Configuration.class)
class MyTest {

  @TempDir
  static Path sharedTempDir;

  public static class Configuration implements QuarkusTestProfile {
    @Override
    public Map<String, String> getConfigOverrides() {
      return Map.of("temp.directory", sharedTempDir.toString());
    }
  }

  @ConfigProperty(name = "temp.directory")
  String tempDirectory;

  @Test
  public void defaultConfiguration() {
      System.out.println(tempDirectory); //Prints actual value
  }
}

@morhei
Copy link
Contributor

morhei commented Mar 9, 2023

Ran into the same issue today.
Guess I'll have to try the workaround.

Edit: can't use that since we use another TestProfile already :/

@leninmehedy
Copy link

Ran into the same issue

@geoand
Copy link
Contributor

geoand commented Oct 19, 2024

This should be fixed when the very important and complicated work @holly-cummins is doing lands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/bug Something isn't working
Projects
Development

No branches or pull requests

8 participants