avoid-duplicate-test-assertions
- Group
- Correctness
- Path
lint/correctness/avoid-duplicate-test-assertions- Default
- On (recommended)
- Origin
- Falcon
- Domain
- test
- Rule
- 55 of 512
Reports repeated identical, side-effect-free assertions in a straight-line block.
Only _test.dart files importing test or flutter_test are inspected.
Calls must resolve to the test framework or matcher package. Comparisons use
the actual and matcher source spelling. Literal/local actual values, standard
matcher constants and simple framework matcher factories are eligible.
Unknown local matcher objects and asynchronous local actuals are excluded.
Intervening non-assertion statements, branches, effectful arguments, awaited
calls, and chained calls end the comparison run.
Invalid
import 'package:test/test.dart';
import 'package:test/test.dart' as t;
void main() {
test('integer', () {
expect(1, 1);
expect(1, 1);
});
test('local variable', () {
final value = true;
expect(value, isTrue);
expect(value, isTrue);
});
test('prefixed', () {
t.expect(false, false);
t.expect(false, false);
});
test('later', () {
expectLater(1, 1);
expectLater(1, 1);
});
test('nonadjacent pure assertions', () {
expect(1, 1);
expect(2, 2);
expect(1, 1);
});
test('three copies', () {
expect(null, null);
expect(null, null);
expect(null, null);
});
}
void matcherExamples() {
test('string matcher factory', () {
expect('value', equals('value'));
expect('value', equals('value'));
});
} expect(1, 1); expect(1, 1); expect(value, isTrue); expect(value, isTrue); t.expect(false, false); t.expect(false, false); expectLater(1, 1); expectLater(1, 1); expect(2, 2); expect(1, 1); expect(null, null); expect(null, null); expect(null, null); expect(null, null); expect('value', equals('value')); expect('value', equals('value'));Valid
import 'package:test/test.dart';
void change() {}
int next() => 1;
class Checker { void expect(Object? a, Object? b) {} }
void main() {
test('assignment resets', () {
var value = 1;
expect(value, 1);
value = 2;
expect(value, 1);
});
test('call resets', () { expect(1, 1); change(); expect(1, 1); });
test('branches', () { if (next() == 1) { expect(1, 1); } else { expect(1, 1); } });
test('first test', () { expect(1, 1); });
test('second test', () { expect(1, 1); });
test('different matcher', () { expect(1, 1); expect(1, 2); });
test('effectful actual', () { expect(next(), 1); expect(next(), 1); });
test('local shadow', () { void expect(Object? a, Object? b) {} expect(1, 1); expect(1, 1); });
test('object member', () { final c = Checker(); c.expect(1, 1); c.expect(1, 1); });
test('await boundary', () async { await expectLater(1, 1); await expectLater(1, 1); });
test('different reason', () { expect(1, 1, reason: 'a'); expect(1, 1, reason: 'b'); });
}
void matcherBoundaries() {
test('effectful matcher', () {
expect(1, equals(next()));
expect(1, equals(next()));
});
test('interpolated actual', () {
expect('${next()}', 1);
expect('${next()}', 1);
});
test('shadowed matcher factory', () {
Object? equals(Object? value) => value;
expect(1, equals(1));
expect(1, equals(1));
});
}
void asynchronousBoundaries(Object queue, Object eventMatcher) {
test('stateful asynchronous matcher', () {
expectLater(queue, eventMatcher);
expectLater(queue, eventMatcher);
});
test('chained side effect breaks run', () {
expectLater(1, 1);
expectLater(1, 1).then((_) { next(); });
expectLater(1, 1);
});
}Configure avoid-duplicate-test-assertions
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-duplicate-test-assertions": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-duplicate-test-assertions: <reason>More correctness rules
- avoid-dynamic-calls
avoid_dynamic_callsrecommendedAvoid method calls or property accesses on a
dynamictarget. - avoid-emit-outside-blocrecommendedbloc
Flags external calls and tear-offs of a Bloc or Cubit's
emitmethod. - avoid-empty-setstaterecommendedflutter
Avoid setState callbacks with empty block bodies.
- avoid-empty-test-groupstest
Reports inline framework groups without any test registrations.
- avoid-global-state
avoid-global-stateDisallow mutable global and static state.
- avoid-hooks-outside-buildrecommendedflutter_hooks
Flags confirmed Flutter hooks outside hook builds, custom hooks, and HookBuilder/HookConsumer builders.
- avoid-incorrect-image-opacityflutter
Flags Opacity directly wrapping a Flutter Image, including named constructors.
- avoid-inherited-widget-in-initstaterecommendedflutter
Avoid inherited-widget subscriptions during initState.