prefer-unique-test-names

Path
lint/suspicious/prefer-unique-test-names
Default
Off, opt in
Origin
Falcon
Domain
test
Rule
416 of 512
test

Reports duplicate test descriptions within a group and constant names in loops.

include-methods (array of strings, default: []) adds custom test registration helpers.

Invalid

example.dartdart
import 'package:test/test.dart';
void main() {
  test('same', () {});
  test('same', () {});
  test("same", () {});
  group('inner', () {
    test('duplicate', () {});
    test('duplicate', () {});
    test('duplicate', () {});
  });
  const description = 'same';
  test(description, () {});
}
Use a unique test description within this group.
3 test('same', () {});
4 test('same', () {});
Use a unique test description within this group.
4 test('same', () {});
5 test("same", () {});
Use a unique test description within this group.
7 test('duplicate', () {});
8 test('duplicate', () {});
Use a unique test description within this group.
8 test('duplicate', () {});
9 test('duplicate', () {});
Use a unique test description within this group.
11 const description = 'same';
12 test(description, () {});

Valid

example.dartdart
import 'package:flutter_test/flutter_test.dart' as t;
void main() {
  t.test('one', () {});
  t.test('two', () {});
  t.group('first', () { t.test('same', () {}); });
  t.group('second', () { t.test('same', () {}); });
  t.testWidgets('widget', (tester) {});
  for (var i = 0; i < 2; i++) { t.test('case $i', () {}); }
  void test(String name, dynamic callback) {}
  test('one', () {});
}

Configure prefer-unique-test-names

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "suspicious": {
        "prefer-unique-test-names": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/suspicious/prefer-unique-test-names: <reason>