prefer-unique-test-names
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 empty) to treat additional method invocations as test cases.
analysis_options.yaml
dart_code_metrics:
rules:
- prefer-unique-test-names:
include-methods:
- customTest
Example
❌ Bad:
void main() {
test('some test', () {});
// LINT: This test has a non-unique name and will be skipped when running from the IDE. Try making the test name unique.
test('some test', () {});
for (final item in [1, 2, 3]) {
// LINT: This test within a loop has a non-unique name. Try making the test name unique per each iteration.
test('broken test', () {});
}
}
✅ Good:
void main() {
test('some test', () {});
group('some group', () {
test('some test', () {});
});
for (final item in [1, 2, 3])
test('good test $item', () {});
}