Menu

1 / 7

Why Passing Tests Doesn't Mean Your Software Is Correct

DEV Community: go·Akkarapon Phikulsri·about 13 hours ago
#WWhy3Rth
#devtogo#devto#dev#coverage#test
Reading 0:00
15s threshold

A Go pricing example show my green tests and high coverage can still miss a business rule defect.

Imagine a checkout service that gives customers a 10% discount on orders of $200 or more. The change has passed code review. The CI pipeline is green and the unit tests report 100% statement coverage.

Then a customer places a $150 order and recieves the discount. The service is working as written but it is not following the business rule.

How could the tests pass ?

The answer is simple

a test can run the code without checking whether the result is correct.

To understand this problem we need to seperate test execution, passing tests, code coverage, assertion quality and software correctness.

A small Go service with a real defect

Our business rule is

Apply a 10% discount only when the order subtotal is at least $200, Otherwise return the original subtotal.

The example stores money as integer cents. It assumes a non negative subtotal and rounds the discount down to a thole cent through integer division.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.