From c85d49633397e09f781a0d8fee313f49207c9821 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 14 Sep 2023 00:53:36 +0100 Subject: [PATCH] daily-email: add 2023-09-09 A lack of tests discourages refactoring --- src/content/daily-email/2023-09-09.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/content/daily-email/2023-09-09.md diff --git a/src/content/daily-email/2023-09-09.md b/src/content/daily-email/2023-09-09.md new file mode 100644 index 00000000..ed5878c3 --- /dev/null +++ b/src/content/daily-email/2023-09-09.md @@ -0,0 +1,26 @@ +--- +title: > + A lack of tests discourages refactoring +pubDate: 2023-09-09 +permalink: > + archive/2023/09/09/a-lack-of-tests-discourages-refactoring +tags: + - automated-testing + - test-driven-development + - refactoring + - software-development +--- + +A common cause of not refactoring code is a lack of test coverage. + +Why change some code if it works? What if we break it whilst refactoring it and introduce a regression? + +If the code has accompanying automated tests, this can't happen. + +The tests should be passing before starting a refactor and should be passing once the refactor is complete. + +If the tests fail, the refactor was unsuccessful and should be reverted. + +If you have a CI pipeline, a failing test should break the pipeline and prevent any further steps if you're doing continuous delivery or deployment whilst signalling to the Developer their refactor was unsuccessful and the pipeline needs to be fixed. + +Without tests, the code could be broken during the refactor, and we wouldn't know.