Skip to main content

missing-test-assertion

added in: 1.6.0
⚙️
Pro+

Warns that there is no assertion in the test.

By default, the rule checks for expect, expectLater, all expectAsync... variants and fail in test and testWidgets methods.

⚙️ Config

Set include-assertions (default is empty) to include additional assertions.

Set include-methods (default is empty) to check additional test methods for missing assertions.

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

Example

❌ Bad:

// LINT: This test does not contain any test assertions. Try adding an assertion or removing this test case.
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);
});