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 the factory 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 🙂
Starting from version 5.10, JUnit 5 offers a
TempDirFactorySPI for customizing how temporary directories are created via the@TempDirannotation.The SPI allows libraries like Jimfs to provide their own implementation, which can be used:
@TempDirannotation via thefactoryattribute, e.g.: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
TempDirFactorychanges so happy to hear your feedback and report back improvements, if you see any 🙂