Skip to main content

Test expectations should not be redundant

ZPA rule for PL/SQL and Oracle SQL · RedundantExpectation

A utPLSQL expectation compares the actual value with the expected one: ut.expect(actual).to_equal(expected). When both arguments are the same expression, the expectation compares a value with itself and always passes: the test checks nothing, usually because of a copy and paste.

This rule reports a ut.expect(...) whose actual value is the same expression as the first argument of its matcher, in test code.

Examples​

Noncompliant Code Example
create package body crate_label_test is
procedure formats_the_code is
l_expected varchar2(20) := 'CR-0042';
l_actual varchar2(20);
begin
l_actual := crate_label(42);
ut.expect(l_actual).to_equal(l_actual); -- Noncompliant
end;
end;
Compliant Solution
create package body crate_label_test is
procedure formats_the_code is
l_expected varchar2(20) := 'CR-0042';
l_actual varchar2(20);
begin
l_actual := crate_label(42);
ut.expect(l_actual).to_equal(l_expected);
end;
end;