Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/userguide/running-unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ Executes all tests from package _HR.TEST_APPLY_BONUS_ and provide outputs to DBM

For details on build-in reporters look at [reporters documentation](reporters.md).

## Keeping uncommited data after test-run

utPLSQL by default runs tests in autonomous transaction and performs automatic rollback to assure that tests do not impact one-another and do not have impact on the current session in your IDE.

If you would like to keep your uncommited data persisted after running tests, you can do so by using `a_force_manual_rollback` flag.
Setting this flag to true has following side-effects:

- test execution is done in current transaction - if while running tests commit or rollback is issued your current session data will get commited too.
- automatic rollback is forced to be disabled in test-run even if it was explicitly enabled by using annotation `--%rollback(manual)

Example invocation:
```sql
begin
ut.run('hr.test_apply_bonus', a_force_manual_rollback => true);
end;
```


This option is not anvailable when running tests using `ut.run` as a table function.

## ut.run functions

The `ut.run` functions provide exactly the same functionality as the `ut.run` procedures.
Expand Down
91 changes: 57 additions & 34 deletions source/api/ut.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ create or replace package body ut is
*/

g_nls_date_format varchar2(4000);
gc_fail_on_errors constant boolean := false;

function version return varchar2 is
begin
Expand Down Expand Up @@ -117,7 +118,6 @@ create or replace package body ut is
a_client_character_set varchar2 := null
) is
pragma autonomous_transaction;
c_fail_on_errors constant boolean := false;
begin
a_reporter := coalesce(a_reporter,ut_documentation_reporter());
ut_runner.run(
Expand All @@ -129,7 +129,7 @@ create or replace package body ut is
a_test_file_mappings,
a_include_objects,
a_exclude_objects,
c_fail_on_errors,
gc_fail_on_errors,
a_client_character_set
);
rollback;
Expand All @@ -147,7 +147,6 @@ create or replace package body ut is
a_client_character_set varchar2 := null
) is
pragma autonomous_transaction;
c_fail_on_errors constant boolean := false;
begin
a_reporter := coalesce(a_reporter,ut_documentation_reporter());
ut_runner.run(
Expand All @@ -159,7 +158,7 @@ create or replace package body ut is
ut_file_mapper.build_file_mappings(a_test_files),
a_include_objects,
a_exclude_objects,
c_fail_on_errors,
gc_fail_on_errors,
a_client_character_set
);
rollback;
Expand Down Expand Up @@ -406,21 +405,39 @@ create or replace package body ut is
a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
) is
l_reporter ut_reporter_base := a_reporter;
begin
run_autonomous(
a_paths,
l_reporter,
ut_utils.boolean_to_int(a_color_console),
a_coverage_schemes,
a_source_file_mappings,
a_test_file_mappings,
a_include_objects,
a_exclude_objects,
a_client_character_set
);
if a_force_manual_rollback then
l_reporter := coalesce(l_reporter,ut_documentation_reporter());
ut_runner.run(
a_paths,
ut_reporters(l_reporter),
a_color_console,
a_coverage_schemes,
a_source_file_mappings,
a_test_file_mappings,
a_include_objects,
a_exclude_objects,
gc_fail_on_errors,
a_client_character_set,
a_force_manual_rollback
);
else
run_autonomous(
a_paths,
l_reporter,
ut_utils.boolean_to_int(a_color_console),
a_coverage_schemes,
a_source_file_mappings,
a_test_file_mappings,
a_include_objects,
a_exclude_objects,
a_client_character_set
);
end if;
if l_reporter is of (ut_output_reporter_base) then
treat(l_reporter as ut_output_reporter_base).lines_to_dbms_output();
end if;
Expand All @@ -436,25 +453,23 @@ create or replace package body ut is
a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
) is
l_reporter ut_reporter_base := a_reporter;
begin
run_autonomous(
ut.run(
a_paths,
l_reporter,
ut_utils.boolean_to_int(a_color_console),
a_color_console,
a_coverage_schemes,
a_source_files,
a_test_files,
ut_file_mapper.build_file_mappings(a_source_files),
ut_file_mapper.build_file_mappings(a_test_files),
a_include_objects,
a_exclude_objects,
a_client_character_set
a_client_character_set,
a_force_manual_rollback
);
if l_reporter is of (ut_output_reporter_base) then
treat(l_reporter as ut_output_reporter_base).lines_to_dbms_output();
end if;
raise_if_packages_invalidated();
end;

procedure run(
Expand All @@ -465,7 +480,8 @@ create or replace package body ut is
a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
) is
begin
ut.run(
Expand All @@ -477,7 +493,8 @@ create or replace package body ut is
a_test_file_mappings,
a_include_objects,
a_exclude_objects,
a_client_character_set
a_client_character_set,
a_force_manual_rollback
);
end;

Expand All @@ -489,7 +506,8 @@ create or replace package body ut is
a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
) is
begin
ut.run(
Expand All @@ -501,7 +519,8 @@ create or replace package body ut is
a_test_files,
a_include_objects,
a_exclude_objects,
a_client_character_set
a_client_character_set,
a_force_manual_rollback
);
end;

Expand All @@ -514,7 +533,8 @@ create or replace package body ut is
a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
) is
begin
ut.run(
Expand All @@ -526,7 +546,8 @@ create or replace package body ut is
a_test_file_mappings,
a_include_objects,
a_exclude_objects,
a_client_character_set
a_client_character_set,
a_force_manual_rollback
);
end;

Expand All @@ -539,7 +560,8 @@ create or replace package body ut is
a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
) is
begin
ut.run(
Expand All @@ -551,7 +573,8 @@ create or replace package body ut is
a_test_files,
a_include_objects,
a_exclude_objects,
a_client_character_set
a_client_character_set,
a_force_manual_rollback
);
end;

Expand Down
18 changes: 12 additions & 6 deletions source/api/ut.pks
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ create or replace package ut authid current_user as
a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
);

procedure run(
Expand All @@ -136,7 +137,8 @@ create or replace package ut authid current_user as
a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
);

procedure run(
Expand All @@ -148,7 +150,8 @@ create or replace package ut authid current_user as
a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
);

procedure run(
Expand All @@ -160,7 +163,8 @@ create or replace package ut authid current_user as
a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
);

procedure run(
Expand All @@ -172,7 +176,8 @@ create or replace package ut authid current_user as
a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
);

procedure run(
Expand All @@ -184,7 +189,8 @@ create or replace package ut authid current_user as
a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
);

/**
Expand Down
26 changes: 16 additions & 10 deletions source/api/ut_runner.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ create or replace package body ut_runner is
return l_result;
end;

procedure finish_run(a_run ut_run) is
procedure finish_run(a_run ut_run, a_force_manual_rollback boolean) is
begin
ut_utils.cleanup_temp_tables;
ut_event_manager.trigger_event(ut_utils.gc_finalize, a_run);
ut_metadata.reset_source_definition_cache;
ut_utils.read_cache_to_dbms_output();
ut_coverage_helper.cleanup_tmp_table();
if not a_force_manual_rollback then
rollback;
end if;
end;


Expand Down Expand Up @@ -83,7 +86,8 @@ create or replace package body ut_runner is
a_include_objects ut_varchar2_list := null,
a_exclude_objects ut_varchar2_list := null,
a_fail_on_errors boolean := false,
a_client_character_set varchar2 := null
a_client_character_set varchar2 := null,
a_force_manual_rollback boolean := false
) is
l_run ut_run;
l_coverage_schema_names ut_varchar2_rows;
Expand Down Expand Up @@ -138,16 +142,18 @@ create or replace package body ut_runner is
a_client_character_set
);
ut_suite_manager.configure_execution_by_path(l_paths, l_run.items);
if a_force_manual_rollback then
l_run.set_rollback_type(ut_utils.gc_rollback_manual, a_force=>true);
end if;

l_run.do_execute();

finish_run(l_run);
rollback;
finish_run(l_run, a_force_manual_rollback);
exception
when others then
finish_run(l_run);
finish_run(l_run, a_force_manual_rollback);
dbms_output.put_line(dbms_utility.format_error_backtrace);
dbms_output.put_line(dbms_utility.format_error_stack);
rollback;
raise;
end;
if a_fail_on_errors and l_run.result in (ut_utils.gc_failure, ut_utils.gc_error) then
Expand Down Expand Up @@ -186,9 +192,9 @@ create or replace package body ut_runner is
l_result boolean := false;
begin
if a_owner is not null and a_package_name is not null and a_procedure_name is not null then

l_result := ut_suite_manager.suite_item_exists( a_owner, a_package_name, a_procedure_name );

end if;

return l_result;
Expand All @@ -200,7 +206,7 @@ create or replace package body ut_runner is
if a_owner is not null and a_package_name is not null then

l_result := ut_suite_manager.suite_item_exists( a_owner, a_package_name );

end if;

return l_result;
Expand All @@ -212,7 +218,7 @@ create or replace package body ut_runner is
if a_owner is not null then

l_result := ut_suite_manager.suite_item_exists( a_owner );

end if;

return l_result;
Expand Down
Loading