1 min read

TDD doesn't mean test every function?

Being only vaguely familiar with it, I was surprised to read today that test-driven development (TDD) doesn't mean you test every function.

Testing Without Mocks describes "test-driving" code in a similar way. The examples proceed with writing a test for a simplified version of a behavior and then implementing the behavior.

That is: Testing a behavior, not a function. That means (as I understand it) that we don't have to test every function—only the one function that implements the program's high-level behavior.

For example: I am working on a Rust interpreter for Lox. It doesn't have many tests. But I could for example write a test that first calls the interpreter to run a program and then validates the output of the program. That validates a behavior, and in doing so exercises a bunch of functions and methods outside the interpreter struct itself—it exercises the interpreter's dependencies. I don't then necessarily need tests for all of those dependencies—although I might want to test some of them separately.