拡張機能研究所

Introducing recommended browser extensions in manga format!

2025/10/15 16:00

Tests Don't Prove Code is Correct? They're Just 'Agreeing'

We think 'All tests passed, so we're safe!' but actually, tests don't prove code is correct - they just show that different pieces of code 'agree' on how things should work. Let's explore this idea casually.

I used to think "If all tests pass, it's perfect, right?" but when I really thought about it, I realized that might not be quite accurate 😳💭

Recently, while writing some "perfectly passing tests," I had a sudden realization. Tests don't actually prove that code is correct - they just show that different pieces of code 'agree' on how things should work

To put it in a common example:

  • The implemented code thinks "this is how it should work"
  • The written tests also think "this is how it should work"

But what if that "this is how it should work" is based on wrong assumptions?
All tests would pass, but the actual behavior could still be weird... this happens more often than you'd think 🥺

In other words, even if all tests show green checkmarks, you might just be holding false confidence.
Isn't that kind of scary? 😱

So I've been trying to shift my perspective lately.
Maybe tests aren't about "proving correctness," but rather about solidifying the intention of "this is how it should work".
They're like markers saying "Hey, if you change this behavior, let me know!" ✨

But here's the tricky part - sometimes that "intention" itself is wrong.
So even if you write tests, blindly trusting them can be dangerous... 🤔

I'm still figuring out the meaning and usage of tests while writing them,
but what do you all think?
Are tests "proof of code correctness"? Or "specification documentation"? Or maybe "guardrails against chaos"? 🛤️💡

If anyone has better ways to work with tests, I'd love to hear them! ✨

Show animated messageON
Wait, seriously!? That's what tests are really about? 😱

Comments

Ataror of Luis

リリー

"Program testing can be used to show the presence of bugs, but never to show their absence" - Dijkstra

Ataror of Brooklynn

ハンナ

Even if it works according to requirements, if the requirements are wrong, it's not the code or developer's fault.

Ataror of Kimberly

キンバリー

I think of tests as defining expectations of "this is how it should work" and creating a mechanism to immediately know when those expectations are broken.

Ataror of Brian

ミア

Passing tests don't necessarily mean it's correct, and failing tests don't necessarily mean it's absolutely wrong. They're feedback telling you when expectations have changed.

Ataror of Christian

クリス

That's why integration tests and acceptance tests are most important. When you evaluate from the customer's perspective, if the requirements are correct, you can tell it's working properly.

Ataror of Robert

ロバート

Good tests aren't constraints - they're like guardrails that guide you in the right direction.

Ataror of George

ジョージ

"Proof that code works as expected" is different. Tests prove whether it works as you think it should, or whether it meets requirements.

Ataror of Sadie

サム

The key point is "you." Are you having AI write your tests?

Ataror of Kingston

グレース

Fixing intentions isn't just for yourself - it's to make them understandable to other developers too. They're there to protect requirements.

Ataror of Sara

サラ

Tests confirm requirements and help everyone understand how to use and how complex systems behave. When touching new codebases, I first run tests to check, but if the tests are bad, I get anxious about proceeding.

Ataror of Sophia

マックス

Documentation isn't verification, and it often becomes outdated the moment it's completed.

Ataror of Luis

リリー

Tests also serve to protect against future changes breaking requirements, and to verify that the system behaves as described in the documentation.

Ataror of Caleb

クロエ

Also, similar to the saying "a bug that isn't fixed becomes a feature" - if a bug remains for a long time and gets depended on, you need to maintain backward compatibility, so you should consider writing tests for that buggy behavior.

Ataror of Brooklynn

ハンナ

You shouldn't leave always-failing tests unattended, and bugs that aren't fixed might not really be bugs.

Ataror of Robert

ロバート

This is a long post about how tests should be written according to requirements.

Ataror of Kingston

グレース

Looking at tests as one big category doesn't make sense. There are various purposes: logical operation verification, project requirement compliance, internal requirement compliance, code path coverage, regression detection, etc. Expecting one test to cover everything is wrong.

Ataror of Kimberly

キンバリー

Also, learning TDD where you write failing tests first would be good. I don't do it much now because it's tedious, but confirming that tests fail is an important mindset that makes you think about what you're actually verifying.

Ataror of Sophia

マックス

This statement is true, but you could also say it doesn't mean much.

Ataror of Luis

リリー

But tests aren't meaningless. It's like how you can't test all economics knowledge in every aspect of life, but within economics itself, it's sufficient.

Ataror of Aidan

エイダン

OP has only one AI-generated post promoting a blog.

Ataror of Leo

レオ

When fixing a bug causes many tests to fail, it's because the tests were written that way.

Ataror of Brooklynn

ハンナ

Tests should only check what's truly necessary and exist to verify that important parts aren't broken by changes, but with the stupid idea of "needing 99.9% coverage," people wastefully test every line too much, requiring massive test fixes just to fix one bug.

Ataror of Sadie

サム

How am I supposed to believe my changes are correct when I have to fix so many tests?

Ataror of Robert

ロバート

Tests fix functionality, its assumptions, and requirements.

Ataror of Brian

ミア

If a new developer breaks something later, tests will warn you first.

Ataror of Kingston

グレース

But if the new developer also changes the tests and gets it through review, there's a fundamental team problem. Tests are just a small part of that.

Ataror of Christian

クリス

The purpose of tests isn't perfect proofs like those created by John Carmack or Donald Knuth, but more like alarms that tell you when someone breaks requirements during new feature development.

Ataror of Sadie

サム

If reviews are bad, there's no integration testing, and QA just clicks buttons, tests won't help.

Ataror of Aiden

エマ

But having no tests is way worse. I've experienced it - it's hell...

Ataror of Brooklynn

ハンナ

I really hate code coverage requirements. When PR reviews are sloppy, tests often become meaningless things just for coverage points.

Ataror of Kimberly

キンバリー

Whether tests are useful depends on:

Ataror of Kimberly

キンバリー

1. Writing tests first according to requirements (TDD) prevents your code and assumptions from just being self-affirming.

Ataror of Kimberly

キンバリー

2. Tools like cucumber and gherkin were created so business people can write and see tests. This connects tests with business requirements.

Ataror of Kimberly

キンバリー

That's why you write tests first. Tests define the functionality, and passing them means implementation is complete. When you can't think of any more failing tests, it's done.

Ataror of Robert

ロバート

After that, tests catch changes that break the specifications.

PICKUP
Related Articles