Aparna
Aparna

Reputation: 11

@TempDir created has null value in JUnit5

I am trying to create temp folder, add files to it and iterate over the files, in one of my test cases. I am currently using Junit5's @TempDir annotation.

@TempDir Path tempDir2;

Further when I tried to create a file in the temp folder, I found that the path of dir is showing null. It should have been actually created in /tmp folder as per my knowledge. Any idea anyone, what could be the cause for tempDir path to be null?

Upvotes: 1

Views: 1194

Answers (1)

zappee
zappee

Reputation: 22668

Probably the reason why TempDir is null is that because you have imported the wrong Test class.

This is the class you need to use: org.junit.jupiter.api.Test.

TempDir won't work with org.junit.Test!

Upvotes: 0

Related Questions