Skip to main content

prefer-unique-test-names

added in: 1.11.0
⚙️
preset: recommended

Warns when the test name is not unique within the same test suite.

A test with a non-unique name will be skipped when running from the IDE. Same goes for tests with non-unique names inside a for loop.

⚙️ Config

Set include-methods (default is none) to treat additional method invocations as test cases.

dart_code_metrics:
...
rules:
...
- prefer-unique-test-names:
include-methods:
- customTest

Example

❌ Bad:

void main() {
test('some test', () {});
test('some test', () {}); // LINT

for (final item in [1, 2, 3])
test('broken test', () {}); // LINT
}

✅ Good:

void main() {
test('some test', () {});

group('some group', () {
test('some test', () {});
});

for (final item in [1, 2, 3])
test('good test $item', () {});
}