missing-assertion

A test checks nothing.

Group
Tests
Runs
On by default
Level
warning
Reads
Tests
Fix
None: what the test should check is the author's choice
Defends
Fidelity: when the code is broken, the test fails.

Why

The test calls code but checks no result, so it fails only when the code throws. An expected exception, a verified test double, a completion callback handed to the code under test, and an assertion in a helper, macro, or callback count as checks, including a test framework's assertion in a helper of another file. A test with none still checks its last call when a failure there reaches the end of the test: an exception the test does not catch, or, where a failure is a value as Rust's Result is, one the test unwraps, passes on with ?, or returns. Rust's let _ = f() throws that failure away.

The fix, as Ur suggests it: if not crashing is the check, say so with an ur-allow: missing-assertion comment; otherwise assert on the result of the call the test is about.

For agents

Give every test an assertion on the result of the code it calls; a test that only calls code can fail only by crashing.

Example

shop/shipping.py
RATES = {"standard": 4.5, "express": 12.0}


class ShippingError(Exception):
    pass


def shipping_cost(method, weight_kg):
    if method not in RATES:
        raise ShippingError(f"unknown method {method}")
    return RATES[method] * max(1, weight_kg)
tests/test_shipping.py
from shop.shipping import ShippingError, shipping_cost


def test_express_shipping():
    try:
        shipping_cost("express", 3)
    except ShippingError:
        pass
What Ur prints
$ ur lint --rule missing-assertion
warning[missing-assertion]: test `test_express_shipping` checks nothing
  --> ./tests/test_shipping.py:4:1-8 test `test_express_shipping`
  = hint: if not crashing is the check, say so with an `ur-allow: missing-assertion` comment; otherwise assert on the result of the call the test is about
  = see: Testing on the Toilet: Effective Testing, Google Testing Blog (2014-05-07), https://testing.googleblog.com/2014/05/testing-on-toilet-effective-testing.html
0 clone classes and 1 test finding in 2 files

Try it in the playground →

Source

Testing on the Toilet: Effective Testing, Google Testing Blog (2014-05-07).