简体   繁体   中英

Mock java.io.File with an in-memory FileSystem. Maybe JimFs

I'm using a third party library that works with java.io.File instances. I'd like to use this library in my unit tests but I don't 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 File with some mocking framework and delegate calls to JimFs but don't know if that will work.

Is there some solution out there to use virtual java.io.File?

您可以使用JUnit TemporaryFolder规则轻松创建在测试方法完成后删除的临时文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM