Skip to main content

missing-test-assertion

added in: 4.21.0
warning

Warns that there is no assertion in the test.

Use include-assertions configuration, if you want to include specific assertions. Defaults to Dart default assertions including expect, expectLater, all expectAsync variants and fail.

Use include-methods configuration, if you want the linter to check particular test methods for missing assertions. Defaults to test and testWidgets methods.

⚙️ Config example

dart_code_metrics:
...
rules:
...
- missing-test-assertion:
include-assertions:
- verify
include-methods:
- customTest

Example

❌ Bad:

test('bad unit test', () {
// Given
final a = 1;
final b = 2;

// When
final c = a + 1;
});

✅ Good:

test('good unit test', () {
// Given
final a = 1;
final b = 2;

// When
final c = a + 1;

// Then : actual assertion
expect(b, c);
});