prefer_correct_test_file_name
This rule flags a file under test/ that declares tests but is not named *_test.dart.
This rule is in the recommended preset.
Why use this rule
Section titled “Why use this rule”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 runsvoid main() { test('should load a user', () {});}void main() { test('should load a user', () {});}// test/support/user_builder.dart — declares no tests, never reportedclass UserBuilder {}Options
Section titled “Options”many_lints: rules: prefer_correct_test_file_name: directories: [test, integration_test]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 |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: prefer_correct_test_file_name: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”format_test_name— Hold test descriptions to a house pattern.avoid_misused_test_matchers— Detect test matchers used with incompatible value types.prefer_test_matchers— Prefer using a Matcher instead of a literal value in expect().require_mirror_test— Detect libraries under lib/ with no matching test file.