Skip to main content

format-test-name

added in: 1.0.0
style
⚙️

Warns when a test or testWidgets name doesn't follow the configured pattern.

Use test-name-pattern configuration, if you want to set name validation for test(...) invocations.

Use test-widgets-name-pattern configuration, if you want to set name validation for testWidgets(...) invocations.

⚙️ Config example

dart_code_metrics:
...
rules:
...
- format-test-name:
test-name-pattern: '^good unit'
test-widgets-name-pattern: '^good widget'

Example

❌ Bad:

test('bad unit test', () {
final a = 1;
final b = 2;
final c = a + 1;
expect(b, c);
});

testWidgets('bad widget test', (WidgetTester tester) async {
await tester.pumpWidget(MyApp());
await tester.pumpAndSettle();
expect(find.text('Welcome'), findsOneWidget);
});

✅ Good:

test('good unit test', () {
final a = 1;
final b = 2;
final c = a + 1;
expect(b, c);
});

testWidgets('good widget test', (WidgetTester tester) async {
await tester.pumpWidget(MyApp());
await tester.pumpAndSettle();
expect(find.text('Welcome'), findsOneWidget);
});