I’m writing a program that creates and edits directories and files in a file system.
I want to write a test that does things like
(1) check if the given directory exists and
(2) create a directory within the existing directory.
What is the best way to test functionality like this?
Is there a way to fake a file system (e.g. in memory?) or would I have to just use a temporary output directory that creates/checks real directories?
You could write wrapper functions for your filesystem interactions, and for testing purposes replace these functions with ones that don’t actually touch the filesystem (but they would keep track of what’s open etc. which your tests can verify).