Skip to main content

missing-test-assertion

added in: 1.6.0
⚙️

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 none) to include additional assertions.

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

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);
});