@teleivo I kindly need your advice on this ticket TRUNK-5875 . In BaseContextSensitiveTest there’s a part of the code that looks like this:
File tempappdir = File.createTempFile("appdir-for-unit-tests-", "");
tempappdir.delete(); // so we can make it into a directory
tempappdir.mkdir(); // turn it into a directory
tempappdir.deleteOnExit(); // clean up when we're done with tests
which is suspected to be the problem being that deleteOnExit() doesn’t properly clean-up a directory. To fix this we need to change to something like this:
final File tempappdir = File.createTempFile("appdir-for-unit-tests-", "");
tempappdir.delete(); // so we can make it into a directory
tempappdir.mkdir(); // turn it into a directory
// clean up when we're done with tests
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
FileUtils.deleteDirectory(tempappdir);
}
catch (IOException ignored) {
}
}));
Where FileUtils is the Apache commons-io version of FileUtils and the same fix needs to be applied to a couple of other place in the code that temporarily create an appdir-for-unit-tests directory.Just wondering if there is a better way to handle this in JUnit 5 which we are migrating to ?
We currently have 2 base classes one for JUnit 4 one for JUnit 5. That is necessary so that module developers can gradually migrate. I assume the issue exists for both base classes.
We might run into the issue discussed here tests failing in core on Windows that tests start failing because JUnit is not able to delete the directory. This happens when our code or tests do not release their connection to files in the temp dir. But let’s see
@dkayiwa I can access BaseContextSensitiveTest for JUnit5 on a master branch pretty well but when I switch to my local branch it disappears.What could be the cause?