5.4. Crippling file path

A crippling file path is one that immobilizes your code, preventing it from running on anybody else’s computer but yours. We all know this problem. I’d be surprised if you’ve never looked at a piece of code and said, “We shouldn’t hardcode that path here,” knowing that the explicit reference to a certain location in the filesystem is going to come back to haunt you later.

Regardless of how well-known this code smell is, it’s surprisingly common. Furthermore, there’s more than one way to cripple your mobility with file paths, so let’s take a look at an example that lets us explore some of them.

5.4.1. Example

The following example shows a simple test case that reads a document from the file-system using an absolute file ...

Get Effective Unit Testing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.