Skip to content

Jimfs support for JUnit Jupiter's TempDirFactory #258

Description

@scordio

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 🙂

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions