-
Notifications
You must be signed in to change notification settings - Fork 283
Open
Labels
Description
Starting from version 5.10, JUnit 5 offers a TempDirFactory
SPI for customizing how temporary directories are created via the @TempDir
annotation.
The SPI allows libraries like Jimfs to provide their own implementation, which can be used:
- On each
@TempDir
annotation via thefactory
attribute, e.g.:
class MyTest {
@TempDir(factory = JimfsTempDirFactory.class)
private Path tempDir;
...
}
- As a meta-annotation, e.g.:
@Target({ ANNOTATION_TYPE, FIELD, PARAMETER })
@Retention(RUNTIME)
@TempDir(factory = JimfsTempDirFactory.class)
@interface JimfsTempDir {
}
class MyTest {
@JimfsTempDir
private Path tempDir;
...
}
- Globally, via a configuration parameter, e.g.:
junit.jupiter.tempdir.factory.default=com.google.common.jimfs.junit.jupiter.JimfsTempDirFactory
You might notice that the JUnit documentation already refers to Jimfs to demonstrate certain use cases.
Would you consider first-party support for such a feature, providing your own factory implementation and maybe even meta-annotation(s)?
Disclaimer: I authored most of the TempDirFactory
changes so happy to hear your feedback and report back improvements, if you see any 🙂
nagromc, lukeu and TobseF