Skip to content

prefer_correct_test_file_name

v1.0.0WarningConfigurableTesting Rules

This rule flags a file under test/ that declares tests but is not named *_test.dart.

This rule is in the recommended preset.

package:test only runs files matching *_test.dart. A file named user_repository_tests.dart or test_user_repository.dart still compiles, still passes analysis, and is silently never executed — the worst failure mode a test can have, because the suite stays green by not running the test at all.

Nothing else catches this. The analyzer is happy, the file has no errors, and CI reports success; the only symptom is a bug shipping past a test that was written to prevent it.

The rule reports only files that actually declare tests — a top-level main containing a test(...), testWidgets(...) or group(...) call. The helpers, fixtures, builders and robots that legitimately live under test/ without being test files are left alone.

See also: package:test, Flutter: testing

// test/user_repository_tests.dart — plural, so it never runs
void main() {
test('should load a user', () {});
}
test/user_repository_test.dart
void main() {
test('should load a user', () {});
}
// test/support/user_builder.dart — declares no tests, never reported
class UserBuilder {}
analysis_options.yaml
many_lints:
rules:
prefer_correct_test_file_name:
directories: [test, integration_test]
Option Type Default Description
directories list of strings [test, integration_test, test_driver] Top-level directories the rule applies to
additional_directories list of strings [] Directories to add to the defaults, instead of restating them

To disable this rule:

many_lints.yaml
rules:
prefer_correct_test_file_name: false

To keep the rule on but skip certain paths, use per-rule exclude.