Skip to content

avoid_focused_tests

v1.1.0 Warning Testing Rules

Warns when a test or group is focused with solo: true. A soloed test silences every sibling in the same file — they are not reported as skipped, they are never considered, and the run still exits zero.

solo is a debugging aid. The defect is committing it, and the diff looks like nothing.

void main() {
// Every other test in this file now silently does not run.
test('the one I am debugging', () {
expect(parse(input), equals(expected));
}, solo: true);
test('handles an empty manifest', () {
expect(parse(''), isEmpty);
});
}

A group focus does the same thing at group scope:

void main() {
group('upload', () {
test('retries once', () {});
}, solo: true);
group('download', () {
// Never runs.
test('streams to disk', () {});
});
}

Narrow the run from the command line. It leaves no trace in the source, so it cannot be committed by accident:

void main() {
test('the one I am debugging', () {
expect(parse(input), equals(expected));
});
test('handles an empty manifest', () {
expect(parse(''), isEmpty);
});
}
Terminal window
dart test --name 'the one I am debugging'
dart test test/upload_test.dart
flutter test --plain-name 'the one I am debugging'

solo: false is the default written out, and suppresses nothing:

void main() {
test('runs like any other', () {}, solo: false);
}

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

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

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.