是否有适用于Java的虚假文件系统框架? [英] Are there any Fake File System frameworks for Java?

查看:91
本文介绍了是否有适用于Java的虚假文件系统框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个大量使用IO操作的项目中引入测试(在这种情况下是文件系统)。系统不断打开/关闭文件,检查文件是否存在,删除它们等等。

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.

好像红宝石的家伙再次这样做了,而且还有正是我在红宝石中要求的是: http://ozmm.org/posts/fakefs.html

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.

Java有什么远程类似的东西吗?

Is there anything remotely similar for Java?

推荐答案

Google拥有Java 7的FileSystemProvider的开源内存实现。 项目名为jimfs

Google has an open-source, in-memory implementation of Java 7's FileSystemProvider. The project is called jimfs.

如果使用Java 6或更早版本,还有另一种选择:我使用过 Apache Commons VFS 才取得巨大成功。它似乎很像自定义的FileSystemProvider,它提到的另一个回答者是在Java 7中。

If you use Java 6 or earlier, there is an alternative: I've used Apache Commons VFS before to great success. It seems to be much like the custom FileSystemProvider another answerer mentioned is in Java 7.

它来自预先加载了几个文件系统实现:文件,RAM,S / FTP和Jar等等。我还看过一个 S3插件

这篇关于是否有适用于Java的虚假文件系统框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆