test_file_not_collected
Reports a test file that the test runner never runs, because its name does not end in _test.dart. Rename it.
- Tier
- blocking
- Scope
- Dart
- Lowest preset
- recommended
- Fix
- none
What it reports
Section titled “What it reports”A file that:
- lies in
test/orintegration_test/; - has a top-level
mainthat declares tests; - has a name that does not end in
_test.dart.
The violation covers the name main.
main declares tests when its body holds, at any depth, a call of one of the test_functions or group_functions with a function literal among its arguments. The name must resolve to a top-level function of a test framework or of a library on the test side, as in test_requires_assertion. A method, a parameter or a local function of that name does not count.
It does not report:
- a file whose name ends in
_test.dart; - a file in
lib/(it has apackage:address),tool/,bin/ortest_driver/, whose drivers the runner pairs by another rule; - a helper beside the tests that has no
main; - a fixture or a tool under
test/whosemaindeclares no test, such as one that starts a program; - a file that gathers other files’ tests by handing on their
main(group('cart', cart.main)), with no test body of its own.
Where the file lies is read from its path: a directory named test above the package root makes a file outside lib/ count as a test file.
dart test and flutter test collect the files that end in _test.dart, and nothing else. A file named cart_tests.dart compiles and looks like the other tests, but it never runs, so it shows up green in no report: its checks protect nothing.
The rule is blocking because the file is a defect of the test suite, and renaming it costs nothing.
Example
Section titled “Example”test/cart_tests.dartvoid main() { test('adds an item', () => expect(Cart().add(1).count, 1));}Corrected: the same file renamed to test/cart_test.dart. There is no fix, since a rename is outside the file.
Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
test_functions |
[test, testWidgets, blocTest] |
The functions whose call declares a test, matched by name as written. |
group_functions |
[group] |
The functions whose call declares a group of tests, matched by name as written. |
assay: rules: test_file_not_collected: exclude: ["test/fixtures/**"] test_functions: [test, testWidgets, blocTest, patrolTest]Suppressing it
Section titled “Suppressing it”Write why on the line directly above main, where the violation is:
// The examples of this folder are run by tool/run_examples.dart.// ignore: assay/test_file_not_collectedvoid main() {// ignore_for_file: assay/test_file_not_collected silences it in a whole file, and // ignore: test_file_not_collected without the prefix works too. See Suppressions.