Are there any Fake File System frameworks for Java?

Viewed 33584

I am introducing tests in a project that makes heavy use of IO operations (the file system, in this case). The system constantly opens/closes files, checks if files exist, deletes them, etcetera.

It soon became obvious that regular mocking wouldn't be of much use, as that would make my tests hard to set up and reason about. On the other hand, having a fake file system would be awesome, and I think, pretty easy to set up.

It seems the ruby guys did it again, and there's exactly what I am asking for in ruby: http://ozmm.org/posts/fakefs.html.

Is there anything remotely similar for Java?

12 Answers

I was googling "Fake java FileSystem" and found this question. Unfortunately this is all I found. So I wrote this fake FileSystem myself: https://github.com/dernasherbrezon/mockfs

I'm using it for simulating IOExceptions during read/write to files. IOException could happen for example due to "no disk space", which is nearly impossible to simulate by other means.

Related