Tests are defined before you start
coding the actual source code.
The program developer writes
an automated test case which
defines the desired
"behaviour" of a function.
This test case will - that's the idea behind the approach -
initially fail, because the code has still to be written.
The major problem or difficulty of this approach is the
task of writing suitable tests. Naturally, the perfect test would check all possible inputs and validate the output. Of course, this is generally not always feasible.