是否有适用于Java的虚假文件系统框架?

编程入门 行业动态 更新时间:2024-10-25 16:20:27
本文介绍了是否有适用于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.

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

It seems the ruby guys did it again, and there's exactly what I am asking for in ruby: ozmm/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的虚假文件系统框架?

本文发布于:2023-11-27 08:41:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637324.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适用于   文件系统   虚假   框架   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!