Skip to main content

format-test-name

added in: 1.0.0
⚙️

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

⚙️ Config

Set test-name-pattern (default is none) to set name validation for test(...) invocations.

Set test-widgets-name-pattern (default is none) to set name validation for testWidgets(...) invocations.

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

This rule requires configuration in order to highlight any issues.

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