You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a test is executed, the named constant is being searched in scope of current user (user executing the tests.
This is not how it is expected to work.
Example of the problem
create or replace package user1.error_codesas
some_error constant integer :=-20001;
end;
/
create or replace package user1.main_packageas
function the_proc (a number , b number ) return number;
end;
/
create or replace package body user1.main_packageas
function the_proc(a number , b number ) return number is
begin
if b =0 then
raise_application_error(error_codes.some_error, 'Cannot use "0"');
end if;
return a/b;
end;
end;
/
create or replace package user1.ut_the_codeas--%suite--%test--%throws(error_codes.some_error)
procedure the_test;
end;
/
create or replace package body user1.ut_the_codeas
procedure the_test is
y number;
begin
y :=main_package.the_proc (1,0);
end;
end;
/
The above test will succeed when called from schema user1.
ut_the_code
the_test [.007 sec] (FAILED - 1)
Failures:
1) the_test
ORA-20001: Cannot use "0"
ORA-06512: at "USER1.MAIN_PACKAGE", line 5
ORA-06512: at "USER1.UT_THE_CODE", line 5
ORA-06512: at line 6
Warnings:
1) ut_the_code.the_test
Invalid parameter value "error_codes.some_error" for "--%throws" annotation. Parameter ignored.
at package "USER1.UT_THE_CODE.THE_TEST", line 4
Finished in .010336 seconds
1 tests, 0 failed, 1 errored, 0 disabled, 1 warning(s)
This is because the value of --%throws annotation is evaluated at runtime within the scope of the user running the code.
A change is needed so that the value is evaluated in scope of the executed UT package schema.
Ideally, we should also allow for below syntax to be valid:
Currently a workaround is possible.
Instead of --%throws(error_codes.some_error) use --%throws(user1.error_codes.some_error)
This will work regardless of user running the test
When a test is executed, the named constant is being searched in scope of current user (user executing the tests.
This is not how it is expected to work.
Example of the problem
The above test will succeed when called from schema user1.
If called from user2,
This is because the value of
--%throws
annotation is evaluated at runtime within the scope of the user running the code.A change is needed so that the value is evaluated in scope of the executed UT package schema.
Ideally, we should also allow for below syntax to be valid:
The text was updated successfully, but these errors were encountered: