avoid_misused_test_matchers
v0.4.0 Warning Fix Testing Rules
Flags expect() calls where the matcher is incompatible with the actual value’s type. For example, using isNull on a non-nullable type, isEmpty on an int, or isList on a String. Misused matchers can cause tests to always pass (hiding bugs) or always fail (making assertions useless).
Why use this rule
Section titled “Why use this rule”A mismatched matcher silently undermines your test suite. expect(42, isNull) will always fail because int is non-nullable, while expect(42, isNotNull) will always pass, giving a false sense of coverage. This rule catches these type mismatches at analysis time before they reach CI.
See also: test package - Matchers
expect(someString, isList); // String is not a Listexpect(someNumber, isEmpty); // int has no isEmptyexpect(someNumber, isNull); // int is non-nullableexpect(someNumber, isNotNull); // always true, redundantexpect(someNumber, hasLength(1)); // int has no lengthexpect(someString, isZero); // String is not a numexpect(someNumber, isTrue); // int is not a boolexpect(someString, isMap); // String is not a Mapexpect(true, isNegative); // bool is not a numexpect(someList, isList);expect(<String, int>{}, isMap);expect(nullableValue, isNull);expect(nullableValue, isNotNull);expect(someList, isEmpty);expect(someString, isEmpty);expect(someList, hasLength(3));expect(someNumber, isZero);expect(5, isPositive);expect(true, isTrue);expect(false, isFalse);Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: avoid_misused_test_matchers: false