From 4d5481c45e389a4470536d9f1b4176efc5b1a7af Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 24 Oct 2022 00:19:35 +0100 Subject: [PATCH] docs(daily-email): add 2022-10-21 --- website/src/daily-emails/2022-10-21.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 website/src/daily-emails/2022-10-21.md diff --git a/website/src/daily-emails/2022-10-21.md b/website/src/daily-emails/2022-10-21.md new file mode 100644 index 00000000..28d38e69 --- /dev/null +++ b/website/src/daily-emails/2022-10-21.md @@ -0,0 +1,23 @@ +--- +title: > + Automated testing and test-driven development are not the same +pubDate: 2022-10-21 +permalink: > + archive/2022/10/21/automated-testing-and-test-driven-development-are-not-the-same +tags: + - testing +--- + +Automated testing is where you write tests to ensure that your code works as expected, which can be re-run as needed and executed automatically without user input. + +Test-driven development (TDD) is when you write the tests before the production code. You see the tests fail and write code until they pass, and then repeat the process. However, TDD is not just about the tests - it's about the design of the code. + +By writing the tests first, you guarantee that the code that you write will be testable, which isn't something that you can't do if the production code is written first. + +You may need to refactor your initial working implementation before it can be tested - which means that you could also break it during that time and need to spend time debugging and fixing any regressions. Ideally, you want the tests in place first before any refactoring, so if something breaks, you'll know because of the failing test. + +TDD keeps your code cleaner and simpler, as you only write enough code to make the tests pass. Once a test is passing, you stop writing code, so you'll end up with less, simpler code as it's easy to know when to stop. + +If you don't write the tests first, you may be tempted to skip writing them completely, leaving untested code or adding `TODO: add test` comments that may never get reviewed. + +Also, where's the fun in writing tests for code that you've already written, that you know are going to pass?