From ae57acc8bc9b61d7d077d43505c572d9052efd72 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 16 Jul 2023 16:44:30 +0100 Subject: [PATCH] daily-email: add 2023-07-16 When writing a failing test, youre designing your code --- src/content/daily-email/2023-07-16.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/content/daily-email/2023-07-16.md diff --git a/src/content/daily-email/2023-07-16.md b/src/content/daily-email/2023-07-16.md new file mode 100644 index 000000000..d4855393e --- /dev/null +++ b/src/content/daily-email/2023-07-16.md @@ -0,0 +1,25 @@ +--- +title: > + When writing a failing test, you're designing your code +pubDate: 2023-07-16 +permalink: > + archive/2023/07/16/when-writing-a-failing-test-youre-designing-your-code +tags: + - automated-testing + - test-driven-development +--- + +When doing test-driven development, you start by writing a failing test and then write the code to make it pass. + +This is the design phase where you ask questions and decide how you want the code to work. + +* Are you going to use a global function or a method on a class? +* Will you create a new class or add a method to an existing class? +* What will it be called? +* Will you use a named method or make the class invokable like a single-method Controller or Action? +* Will it accept any parameters? +* If so, what will the parameters be, what will they be named, and will they take any default values? +* Will it return a value? +* Should it throw an Exception? + +You might iterate on the design and change it as you write more assertions or tests, but take the opportunity to decide how you want the code to work at this point before you start writing the implementation.