over-specified-verify

A verification fixes every argument of the call it verifies.

Group
Tests
Runs
On by default
Level
note
Reads
Tests
Fix
None: which arguments the behavior depends on is the author's to say
Defends
Resilience: the test fails only when the code is broken.

Why

The verification gives three or more arguments and lets none of them vary, so the test fails when an argument the behavior does not depend on changes, and a reader cannot tell which argument matters.

The fix, as Ur suggests it: replace the arguments the behavior does not depend on with matchers that accept anything.

For agents

When verifying a call on a test double, state only the arguments the behavior under test depends on and let the rest vary with the framework's argument matchers.

Example

shop/checkout.py
def checkout(cart, payments, receipts, stock):
    stock.reserve(cart.items)
    charge = payments.charge(cart.total)
    receipts.send(cart.owner, charge.reference, cart.total)
    return charge.reference
tests/test_checkout.py
from unittest.mock import Mock

from shop.checkout import checkout
from shop.basket import Cart, Stock
from shop.payments import FakePayments


def test_checkout_sends_a_receipt_to_the_owner():
    receipts = Mock()
    checkout(Cart("ada", 24), FakePayments("ref-7"), receipts, Stock())
    receipts.send.assert_called_once_with("ada", "ref-7", 24)
What Ur prints
$ ur lint --rule over-specified-verify
note[over-specified-verify]: the verification with `assert_called_once_with` in test `test_checkout_sends_a_receipt_to_the_owner` fixes all 3 arguments, so it fails when one the behavior does not depend on changes
  --> ./tests/test_checkout.py:11:5 test `test_checkout_sends_a_receipt_to_the_owner`
  = hint: replace the arguments the behavior does not depend on with matchers that accept anything
  = see: Testing on the Toilet: Only Verify Relevant Method Arguments, Google Testing Blog (2018-06-26), https://testing.googleblog.com/2018/06/testing-on-toilet-only-verify-relevant.html
0 clone classes and 1 test finding in 2 files

Try it in the playground →

Source

Testing on the Toilet: Only Verify Relevant Method Arguments, Google Testing Blog (2018-06-26).