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 suite stays green by not running the test at all. Nothing else catches this: the analyzer is happy and CI reports success.
// test/user_repository_tests.dart — plural, so the runner never picks it upvoid main() { test('should load a user', () {});}// test/test_user_repository.dart — prefix instead of suffix, same resultvoid main() { test('should load a user', () {});}void main() { test('should load a user', () {});}Files that declare no tests are never reported
Section titled “Files that declare no tests are never reported”The rule reports only a file whose top-level main contains a test(...),
testWidgets(...) or group(...) call. Helpers, fixtures, builders and robots
live under test/ without being test files, and are left alone:
// test/support/user_builder.dart — no tests declared, never reportedclass UserBuilder { UserBuilder withName(String name) => this;}Extending the directories checked
Section titled “Extending the directories checked”By default the rule looks at test/, integration_test/ and test_driver/.
A project with a suite elsewhere adds it:
many_lints: rules: prefer_correct_test_file_name: additional_directories: [e2e]rules: prefer_correct_test_file_name: additional_directories: [e2e]// e2e/checkout_flow.dart — now reported; rename to checkout_flow_test.dartvoid main() { test('completes a checkout', () {});}Use directories: instead to replace the defaults outright rather than add to
them.
See also: package:test, Flutter: testing
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.