Test Files
JUnit 4
The TemporaryFolder rule allows creating testing folders.
@Rule
public TemporaryFolder folder = new TemporaryFolder();
file = folder.newFile("/file.txt");
JUnit 5
The TempDir annotation initializes a testing folder.
@TempDir
public static File folder;
Which can be used for creating test files:
file = new File(folder, "/file.txt");
Last updated
Was this helpful?