Skip to content

empty_test_group

Reports a group of tests that declares no test. Write the missing tests, or delete the group.

Tier
advisory
Scope
Dart
Lowest preset
recommended
Fix
none

A group of tests that declares no test. The violation is on the name of the group function in the call.

  • A group is a call of one of the group_functions that resolves to a test framework or to the test side, with a function literal among its arguments: its body.
  • The body declares a test when it holds, at any depth, a call of a name in test_functions or group_functions, whatever the name resolves to: suite.test(…) on an object counts too.
  • A nested group counts as a test and is judged itself, so of two nested empty groups only the inner one is reported.
  • Whatever the rule cannot see into counts as a test, as test_requires_assertion reads a body for an assertion: a helper of the same file that declares a test, through any number of helpers; a function or method declared in another file of the test side; a function value the file cannot read, such as a parameter of a function around the group.

It does not report:

  • a group with a test at any depth, in a loop as well;
  • a group whose test comes from a helper, of this file or of another file of the test side;
  • a skipped group, given a skip other than false or null: the runner reports it as skipped;
  • a group whose body is a name, group('cart', cartTests), not a function literal;
  • a method or a local function named group, or a call outside the test side.

An empty group passes. The runner counts no failure in it, and the report shows a green group that checks nothing. It is usually a group whose tests were deleted, moved or never written, sometimes with a setUp left behind. The rule is advisory: nothing fails, but nothing is checked either.

Violating
group('checkout', () {
setUp(() => cart = Cart());
});
Corrected
group('checkout', () {
setUp(() => cart = Cart());
test('starts empty', () => expect(cart.isEmpty, isTrue));
});

There is no fix: only you know which tests are missing.

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:
empty_test_group:
exclude: ["test/fixtures/**"]
test_functions: [test, testWidgets, blocTest, patrolTest]

Write why on the line directly above the suppression, which goes above the line of the group function:

// The group is filled by the generated cases of the build step.
// ignore: empty_test_group
group('generated', () {});

// ignore_for_file: assay/empty_test_group silences it in a whole file, and // ignore: assay/empty_test_group with the prefix works too. See Suppressions.