Skip to content

Commit 9308662

Browse files
committed
Fixed examples.
Moved/fixed some constants.
1 parent 2537ced commit 9308662

File tree

5 files changed

+85
-103
lines changed

5 files changed

+85
-103
lines changed

examples/developer_examples/RunExampleComplexSuiteWithCustomReporter.sql

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,44 @@ set echo off
1313
@@ut_custom_reporter.tpb
1414

1515
declare
16-
suite1 ut_logical_suite;
17-
suite2 ut_logical_suite;
18-
suite_complex ut_logical_suite;
19-
l_reporter ut_output_reporter_base;
20-
l_listener ut_event_listener;
21-
l_run ut_run;
16+
l_parent_suite ut_logical_suite;
17+
l_suite ut_suite;
18+
l_test ut_test;
19+
l_reporter ut_output_reporter_base;
20+
l_run ut_run;
2221
begin
23-
suite1 := ut_logical_suite(a_object_owner=>null, a_object_name => null, a_name => null, a_description => 'Test Suite 1', a_path => null);
24-
25-
suite1.add_item(
26-
ut_test(a_object_name => 'ut_exampletest'
27-
,a_name => 'ut_exAmpletest'
28-
,a_description => 'Example test1'
29-
,a_before_test_proc_name => 'Setup'
30-
,a_after_test_proc_name => 'tEardown')
31-
);
32-
33-
suite2 := ut_logical_suite(a_object_owner=>null, a_object_name => null, a_name => null, a_description => 'Test Suite 2', a_path => null);
34-
35-
suite2.add_item(
36-
ut_test(
37-
a_object_name => 'UT_EXAMPLETEST2',
38-
a_name => 'UT_EXAMPLETEST',
39-
a_description => 'Another example test',
40-
a_before_test_proc_name => 'SETUP',
41-
a_after_test_proc_name => 'TEARDOWN')
42-
);
43-
44-
suite_complex := ut_logical_suite( a_object_owner=>null, a_object_name => null, a_name => null, a_description => 'Complex Test Suite', a_path => null);
45-
suite_complex.items := ut_suite_items(suite1, suite2);
22+
ut_event_manager.initialize();
23+
l_parent_suite := ut_logical_suite( a_object_owner=>null, a_object_name => null, a_name => 'complex_test_suite', a_path => null);
24+
25+
l_suite := ut_suite(user, 'ut_exampletest');
26+
l_test := ut_test(user, 'ut_exampletest','ut_exAmpletest');
27+
l_test.description := 'Example test1';
28+
l_test.before_test_list := ut_executables(ut_executable(user, 'ut_exampletest','Setup',ut_utils.gc_before_test));
29+
l_test.after_test_list := ut_executables(ut_executable(user, 'ut_exampletest','tEardown',ut_utils.gc_after_test));
30+
31+
l_suite.add_item(l_test);
32+
l_parent_suite.add_item(l_suite);
33+
34+
35+
l_suite := ut_suite(user, 'ut_exampletest2');
36+
l_test := ut_test(user, 'UT_EXAMPLETEST2','UT_EXAMPLETEST');
37+
l_test.before_test_list := ut_executables(ut_executable(user, 'UT_EXAMPLETEST2','SETUP',ut_utils.gc_before_test));
38+
l_test.after_test_list := ut_executables(ut_executable(user, 'UT_EXAMPLETEST2','TEARDOWN',ut_utils.gc_after_test));
39+
40+
l_suite.add_item(l_test);
41+
l_parent_suite.add_item(l_suite);
4642

4743
-- provide a reporter to process results
4844
l_reporter := ut_custom_reporter(a_tab_size => 2);
49-
l_listener := ut_event_listener(ut_reporters(l_reporter));
50-
l_run := ut_run(ut_suite_items(suite_complex));
51-
l_run.do_execute(l_listener);
45+
ut_event_manager.add_listener(l_reporter);
46+
l_run := ut_run(ut_suite_items(l_parent_suite));
47+
l_run.do_execute();
48+
ut_event_manager.trigger_event(ut_utils.gc_finalize, l_run);
5249
l_reporter.lines_to_dbms_output();
5350
end;
5451
/
5552

5653
drop type ut_custom_reporter;
5754
drop package ut_exampletest;
5855
drop package ut_exampletest2;
56+
exec dbms_session.reset_package;

examples/developer_examples/RunExampleTestSuite.sql

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,37 @@ set echo off
1111
@@ut_exampletest2.pkb
1212

1313
declare
14-
suite ut_logical_suite;
15-
listener ut_event_listener := ut_event_listener(ut_reporters());
16-
test_item ut_test;
17-
expectation ut_expectation_result;
14+
l_suite ut_logical_suite;
15+
l_test ut_test;
16+
l_expectation ut_expectation_result;
1817
begin
19-
suite := ut_logical_suite(a_object_owner=>null, a_object_name => 'ut_exampletest', a_name => null, a_description => 'Test Suite Name',a_path => null);
18+
l_suite := ut_suite(user, 'ut_exampletest');
19+
l_suite.description := 'Test Suite Name';
20+
l_test := ut_test(user, 'ut_exampletest','ut_exAmpletest');
21+
l_test.description := 'Example test1';
22+
l_test.before_test_list := ut_executables(ut_executable(user, 'ut_exampletest','Setup',ut_utils.gc_before_test));
23+
l_test.after_test_list := ut_executables(ut_executable(user, 'ut_exampletest','tEardown',ut_utils.gc_after_test));
24+
l_suite.add_item(l_test);
2025

21-
suite.add_item(
22-
ut_test(a_object_name => 'ut_exampletest'
23-
,a_name => 'ut_exAmpletest'
24-
,a_description => 'Example test1'
25-
,a_before_test_proc_name => 'Setup'
26-
,a_after_test_proc_name => 'tEardown')
27-
);
26+
l_test := ut_test(user, 'UT_EXAMPLETEST2','ut_exAmpletest');
27+
l_test.description := 'Another example test';
28+
l_test.before_test_list := ut_executables(ut_executable(user, 'UT_EXAMPLETEST2','SETUP',ut_utils.gc_before_test));
29+
l_test.after_test_list := ut_executables(ut_executable(user, 'UT_EXAMPLETEST2','TEARDOWN',ut_utils.gc_after_test));
30+
l_suite.add_item(l_test);
2831

29-
suite.add_item(
30-
ut_test(
31-
a_object_name => 'UT_EXAMPLETEST2',
32-
a_name => 'UT_EXAMPLETEST',
33-
a_description => 'Another example test',
34-
a_before_test_proc_name => 'SETUP',
35-
a_after_test_proc_name => 'TEARDOWN')
36-
);
37-
38-
suite.do_execute(listener);
32+
l_suite.do_execute();
3933

4034
-- No reporter used in this example so outputing the results manually.
41-
for test_idx in suite.items.first .. suite.items.last loop
42-
test_item := treat(suite.items(test_idx) as ut_test);
35+
for test_idx in l_suite.items.first .. l_suite.items.last loop
36+
l_test := treat(l_suite.items(test_idx) as ut_test);
4337
dbms_output.put_line('---------------------------------------------------');
44-
dbms_output.put_line('Test:' || test_item.item.form_name);
45-
dbms_output.put_line('Result: ' || ut_utils.test_result_to_char(test_item.result));
38+
dbms_output.put_line('Test:' || l_test.item.form_name);
39+
dbms_output.put_line('Result: ' || ut_utils.test_result_to_char(l_test.result));
4640
dbms_output.put_line('expectation Results:');
47-
for i in 1 .. test_item.failed_expectations.count loop
48-
expectation := test_item.failed_expectations(i);
49-
dbms_output.put_line(i || ' - result: ' || ut_utils.test_result_to_char(expectation.result));
50-
dbms_output.put_line(i || ' - Message: ' || expectation.message);
41+
for i in 1 .. l_test.failed_expectations.count loop
42+
l_expectation := l_test.failed_expectations(i);
43+
dbms_output.put_line(i || ' - result: ' || ut_utils.test_result_to_char(l_expectation.result));
44+
dbms_output.put_line(i || ' - Message: ' || l_expectation.message);
5145
end loop;
5246
end loop;
5347
dbms_output.put_line('---------------------------------------------------');

examples/developer_examples/RunExampleTestSuiteWithCompositeReporter.sql

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,23 @@ declare
1515
suite ut_logical_suite;
1616
l_doc_reporter ut_output_reporter_base := ut_documentation_reporter();
1717
l_tc_reporter ut_output_reporter_base := ut_teamcity_reporter();
18-
l_listener ut_event_listener := ut_event_listener(ut_reporters(l_doc_reporter, l_tc_reporter));
1918
l_run ut_run;
2019
begin
21-
suite := ut_logical_suite(a_object_owner=>null, a_object_name => 'ut_exampletest', a_name => null, a_description => 'Test Suite Name',a_path => null);
20+
ut_event_manager.initialize();
21+
ut_event_manager.add_listener(l_doc_reporter);
22+
ut_event_manager.add_listener(l_tc_reporter);
2223

23-
suite.add_item(
24-
ut_test(a_object_name => 'ut_exampletest'
25-
,a_name => 'ut_exAmpletest'
26-
,a_description => 'Example test1'
27-
,a_before_test_proc_name => 'Setup'
28-
,a_after_test_proc_name => 'tEardown')
29-
);
24+
suite := ut_suite(user, 'ut_exampletest');
25+
suite.description := 'Test Suite Name';
3026

31-
suite.add_item(
32-
ut_test(
33-
a_object_name => 'UT_EXAMPLETEST2',
34-
a_name => 'UT_EXAMPLETEST',
35-
a_description => 'Another example test',
36-
a_before_test_proc_name => 'SETUP',
37-
a_after_test_proc_name => 'TEARDOWN')
38-
);
27+
suite.add_item(ut_test(user,'ut_exampletest','ut_exAmpletest'));
28+
suite.add_item(ut_test(user, 'UT_EXAMPLETEST2','UT_EXAMPLETEST'));
3929

4030
-- provide a reporter to process results
4131
l_run := ut_run(ut_suite_items(suite));
42-
l_run.do_execute(l_listener);
32+
l_run.do_execute();
33+
34+
ut_event_manager.trigger_event(ut_utils.gc_finalize, l_run);
4335
l_doc_reporter.lines_to_dbms_output(0,0);
4436
l_tc_reporter.lines_to_dbms_output(0,0);
4537
end;

examples/developer_examples/RunExampleTestSuiteWithCustomReporter.sql

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,34 @@ set echo off
1414
@@ut_custom_reporter.tpb
1515

1616
declare
17-
suite ut_logical_suite;
17+
l_suite ut_logical_suite;
18+
l_test ut_test;
1819
l_reporter ut_output_reporter_base;
19-
l_listener ut_event_listener;
2020
l_run ut_run;
2121
begin
22+
ut_event_manager.initialize();
2223
-- Install ut_custom_reporter first from example folder
2324

24-
suite := ut_logical_suite(a_object_owner=>null, a_object_name => 'ut_exampletest', a_name => null, a_description => 'Test Suite Name',a_path => null);
25+
l_suite := ut_suite(user, 'ut_exampletest');
2526

26-
suite.add_item(
27-
ut_test(a_object_name => 'ut_exampletest'
28-
,a_name => 'ut_exAmpletest'
29-
,a_description => 'Example test1'
30-
,a_before_test_proc_name => 'Setup'
31-
,a_after_test_proc_name => 'tEardown')
32-
);
27+
l_test := ut_test(user, 'ut_exampletest','ut_exAmpletest');
28+
l_test.description := 'Example test1';
29+
l_test.before_test_list := ut_executables(ut_executable(user, 'ut_exampletest','Setup',ut_utils.gc_before_test));
30+
l_test.after_test_list := ut_executables(ut_executable(user, 'ut_exampletest','tEardown',ut_utils.gc_after_test));
31+
l_suite.add_item(l_test);
3332

34-
suite.add_item(
35-
ut_test(
36-
a_object_name => 'UT_EXAMPLETEST2',
37-
a_name => 'UT_EXAMPLETEST',
38-
a_description => 'Another example test',
39-
a_before_test_proc_name => 'SETUP',
40-
a_after_test_proc_name => 'TEARDOWN')
41-
);
33+
l_test := ut_test(user, 'UT_EXAMPLETEST2','ut_exAmpletest');
34+
l_test.description := 'Another example test';
35+
l_test.before_test_list := ut_executables(ut_executable(user, 'ut_exampletest','SETUP',ut_utils.gc_before_test));
36+
l_test.after_test_list := ut_executables(ut_executable(user, 'ut_exampletest','TEARDOWN',ut_utils.gc_after_test));
37+
l_suite.add_item(l_test);
4238

4339
-- provide a reporter to process results tabbing each hierarcy level by tab_size
4440
l_reporter := ut_custom_reporter(a_tab_size => 2);
45-
l_listener := ut_event_listener(ut_reporters(l_reporter));
46-
l_run := ut_run(ut_suite_items(suite));
47-
l_run.do_execute(l_listener);
41+
ut_event_manager.add_listener(l_reporter);
42+
l_run := ut_run(ut_suite_items(l_suite));
43+
l_run.do_execute();
44+
ut_event_manager.trigger_event(ut_utils.gc_finalize, l_run);
4845
l_reporter.lines_to_dbms_output(0,0);
4946
end;
5047
/
@@ -54,3 +51,4 @@ end;
5451
drop type ut_custom_reporter;
5552
drop package ut_exampletest;
5653
drop package ut_exampletest2;
54+
exec dbms_session.reset_package;

source/core/ut_utils.pks

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ create or replace package ut_utils authid definer is
3030
gc_before_before_all constant t_event_name := 'before_before_all';
3131
gc_before_before_each constant t_event_name := 'before_before_each';
3232
gc_before_before_test constant t_event_name := 'before_before_test';
33-
gc_before_test constant t_event_name := 'before_test';
3433
gc_before_test_execute constant t_event_name := 'before_test_execute';
3534
gc_before_after_test constant t_event_name := 'before_after_test';
3635
gc_before_after_each constant t_event_name := 'before_after_each';
@@ -40,7 +39,6 @@ create or replace package ut_utils authid definer is
4039
gc_after_before_all constant t_event_name := 'after_before_all';
4140
gc_after_before_each constant t_event_name := 'after_before_each';
4241
gc_after_before_test constant t_event_name := 'after_before_test';
43-
gc_after_test constant t_event_name := 'after_test';
4442
gc_after_test_execute constant t_event_name := 'after_test_execute';
4543
gc_after_after_test constant t_event_name := 'after_after_test';
4644
gc_after_after_each constant t_event_name := 'after_after_each';
@@ -50,7 +48,9 @@ create or replace package ut_utils authid definer is
5048
subtype t_executable_type is varchar2(30);
5149
gc_before_all constant t_executable_type := 'before_all';
5250
gc_before_each constant t_executable_type := 'before_each';
51+
gc_before_test constant t_executable_type := 'before_test';
5352
gc_test_execute constant t_executable_type := 'test_execute';
53+
gc_after_test constant t_executable_type := 'after_test';
5454
gc_after_each constant t_executable_type := 'after_each';
5555
gc_after_all constant t_executable_type := 'after_all';
5656

0 commit comments

Comments
 (0)