Skip to content

avoid_focused_tests

v1.1.0 Warning Testing Rules

Warns when a test or group is focused with solo:. This is the mirror of avoid_skipped_tests and the more dangerous half.

A skipped test silences itself, and the runner’s summary at least counts it. A soloed test silences every sibling in the file — they are not reported as skipped so much as never considered, and the run still exits zero. One word turns a file of forty assertions into a file of one.

solo is a debugging aid: it is how you narrow a run while chasing a single failure. The defect is committing it, and nobody intends to, which is exactly why it needs a rule rather than a code-review habit. The diff looks like nothing.

There is deliberately no option to permit it. Unlike a skip, a focus has no documented-and-therefore-tolerable form — a reason string would not make the other tests run.

See also: package:test — running one test | eslint-plugin-jest: no-focused-tests

// Every other test in this file now silently does not run.
test('the one I am debugging', () {
expect(parse(input), equals(expected));
}, solo: true);
// Same at group level.
group('upload', () {
// ...
}, solo: true);
// Narrow the run from the command line instead — it leaves no trace in the
// source, so it cannot be committed by accident.
//
// dart test --name 'the one I am debugging'
// dart test test/upload_test.dart
test('the one I am debugging', () {
expect(parse(input), equals(expected));
});

solo: false is never reported: it is the default written out, and suppresses nothing.

This rule is in the recommended preset, so it is on with preset: recommended, preset: opinionated or preset: pedantic. Add it to preset: core with avoid_focused_tests: true.

To turn it off:

many_lints.yaml
rules:
avoid_focused_tests: false

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