Mock java.io.File with a file system in memory. Maybe JimFs

I use a third-party library that works with java.io.File instances. I would like to use this library in my unit tests, but I do not want it to create files on disk.

My first idea was to use JimFs to mock the file system, but it does not support java.io.File.

My second idea was to mock the File with some mocking structure and delegate JimFs calls, but I don't know if this will work.

Is there any solution for using virtual java.io.File?

+6
source share
1 answer

You can use the JUnit TemporaryFolder rule to easily create temporary files that are deleted after the test method completes.

+2
source

Source: https://habr.com/ru/post/983414/


All Articles