oliverdavies.uk/source/_daily_emails/2023-05-06.md

22 lines
1.1 KiB
Markdown
Raw Permalink Normal View History

2024-01-03 20:00:00 +00:00
---
title: >
2024-09-08 22:09:54 +00:00
Why it's important to see the test fail
2024-01-03 20:00:00 +00:00
pubDate: 2023-05-06
permalink: >-
daily/2023/05/06/why-its-important-to-see-the-test-fail
2024-01-03 20:00:00 +00:00
tags:
2024-09-08 22:09:54 +00:00
- automated-testing
- test-driven-development
2024-01-03 20:00:00 +00:00
---
With automated testing and test-driven development, it's important to see a test fail.
If a test passes straight away, how do you know that you're testing the right thing? You could be accidentally testing a different piece of functionality, or it could be a false positive.
If the functionality already exists, do you need another test for it?
When you see a test fail, you know that the functionality hasn't been implemented, that you're testing the correct thing, and you have a clear goal to work towards.
If you're fixing a bug, writing a test and seeing it fail verifies the bug exists and that, once the bug is fixed, the test will pass.
Usually, you can anticipate why a test will fail as it evolves and know when it will pass. If a test passes before I expect, I'm immediately sceptical and will look into why rather than assuming it passed for the right reasons.