top | item 47071385

(no title)

WolfOliver | 11 days ago

That is a valid point. This is exactly when you should use a mock.

discuss

order

1718627440|11 days ago

Wouldn't it be easier to just create a small ISO file, mount it and just fill that up?

explodes|11 days ago

When your code uses inversion of control, which can allow your code to inject different versions of your dependencies, such as a mocked disk API, or network resource, the code is often more testable because of the separation of concerns, and thoughtful design.

I would answer your question by stating your alternative _might_ be an easier test to write now, but amortizing the (already low) cost of having a code written with first practices in mind will be much easier to work with in the long run. Including across small and large teams. Ultimately we want our code to be reliable and scalable, and we can do that by making our code testable and maintainable.

zbentley|10 days ago

Possible, yes, but certainly not easier—especially not if the test harness doesn’t manage filesystems anywhere else.

And even then, that’s still a behavior mock, of a kind. There are lots of ways in which a dummy ISO mount behaves much unlike filesystems your deployed code might run on. You could address those issues, but doing so is very laborious and starts requiring more and more specialized code. Unless the code under test is part of a database storage engine or something, it’s likely even less worth it.

viraptor|10 days ago

You'll need permissions to mount things. It may be restricted in CI environment, so I wouldn't rely on it.