Skip to content

Tests that assert nothing, or assert a constant ​

Tests and verification: one of the ways AI coding agents bloat software, from lessloc's pattern catalog. lessloc catches it as empty-test.

What makes tests that assert nothing, or assert a constant a bad practice? ​

The standard that calls it a bad practice: Carr, TDD anti-patterns: The Liar.

What does lessloc do about tests that assert nothing, or assert a constant? ​

lessloc catches it as empty-test.

  • empty-test (tier 1): A test that asserts nothing or only a constant, or one that mocks the code it tests.

Examples ​

Caught as empty-test:

python
def test_total():
    total([1, 2])


def test_sum():
    assert True

Written well:

python
def test_total():
    assert total([1, 2]) == 3


def test_import_runs():
    import json

Caught as empty-test:

python
def test_render():
    expected = """\
[a]
b = 1
"""
    render(expected)

Written well:

python
def test_render():
    expected = """\
[a]
b = 1
"""
    assert render() == expected

Caught as empty-test:

js
import { test } from "node:test";
test("adds", () => {
  add(1, 2);
});

Written well:

js
import { test } from "node:test";
import assert from "node:assert";
test("adds", () => {
  assert.equal(add(1, 2), 3);
});

The other patterns in Tests and verification:

Released under the Apache-2.0 license. · llms.txt