Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-2113

@TempDir does not correctly work

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.22.2, 3.0.0-M7
    • None
    • JUnit 5.x support
    • None

    Description

      Having the following test:

      class TempDirTest {
        @Test
        void testTempDir(@TempDir Path tmpdir) {
          System.out.println("@TempDir : " + tmpdir);
          System.out.println("java.io.tmpdir : " + System.getProperty("java.io.tmpdir"));
      
          Path actual = tmpdir.getParent().toAbsolutePath();
          Path expected = Path.of(System.getProperty("java.io.tmpdir"));
      
          Assertions.assertEquals(expected, actual);
        }
      }
      

      If I run via:

      mvn -Djava.io.tmpdir=/tmp/custom clean test
      

      within the following environment:

      Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
      Maven home: /Users/khm/tools/maven
      Java version: 11.0.15, vendor: Azul Systems, Inc., runtime: /Users/khm/.sdkman/candidates/java/11.0.15-zulu/zulu-11.jdk/Contents/Home
      Default locale: en_DE, platform encoding: UTF-8
      OS name: "mac os x", version: "12.4", arch: "aarch64", family: "mac"
      

      The given test succeeds.

      If I use the following environment (changed JDK version):

      Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
      Maven home: /Users/khm/tools/maven
      Java version: 17.0.4, vendor: Azul Systems, Inc., runtime: /Users/khm/.sdkman/candidates/java/17.0.4-zulu/zulu-17.jdk/Contents/Home
      Default locale: en_DE, platform encoding: UTF-8
      OS name: "mac os x", version: "12.4", arch: "aarch64", family: "mac"
      

      The given test fails:

      [INFO] -------------------------------------------------------
      [INFO] Running org.example.TempDirTest
      @TempDir : /var/folders/wj/73qxv5hd6p573p9ytbf4kcgh0000gn/T/junit2987236559648574880
      java.io.tmpdir : /tmp/custom
      [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.027 s <<< FAILURE! - in org.example.TempDirTest
      [ERROR] testTempDir{Path}  Time elapsed: 0.023 s  <<< FAILURE!
      org.opentest4j.AssertionFailedError: expected: </tmp/custom> but was: </var/folders/wj/73qxv5hd6p573p9ytbf4kcgh0000gn/T>
      	at org.example.TempDirTest.testTempDir(TempDirTest.java:18)
      
      [INFO] 
      [INFO] Results:
      

      I've checked that with different combinations:

      I have create a full [working example](https://github.com/khmarbaise/tempdir-annotation) which contains appropriate named branches for the different combinations.

      I've also tested the same combinations with JDK 17/11 from liberica with the same result. Also with JDK18 the test fails.

      After more checking I found out that via the standalone launcher, there is no problem at all. (no difference between jdk versions).

      java -Djava.io.tmpdir=/tmp/custom -jar ~/.m2/repository/org/junit/platform/junit-platform-console-standalone/1.9.0/junit-platform-console-standalone-1.9.0.jar -cp classes:target/test-classes --scan-classpath
      

      The output:

      @TempDir : /tmp/custom/junit17756560401872268189
      java.io.tmpdir : /tmp/custom
      
      Thanks for using JUnit! Support its development at https://junit.org/sponsoring
      
      ╷
      ├─ JUnit Jupiter ✔
      │  └─ TempDirTest ✔
      │     └─ testTempDir(Path) ✔
      ├─ JUnit Vintage ✔
      └─ JUnit Platform Suite ✔
      
      Test run finished after 51 ms
      [         4 containers found      ]
      [         0 containers skipped    ]
      [         4 containers started    ]
      [         0 containers aborted    ]
      [         4 containers successful ]
      [         0 containers failed     ]
      [         1 tests found           ]
      [         0 tests skipped         ]
      [         1 tests started         ]
      [         0 tests aborted         ]
      [         1 tests successful      ]
      [         0 tests failed          ]
      
      

      Has someone an Idea what could cause such thing?

      Attachments

        Activity

          People

            Unassigned Unassigned
            khmarbaise Karl Heinz Marbaise
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: