Skip to content

Commit 66a9e58

Browse files
committed
Add Type Testing
1 parent ff22e59 commit 66a9e58

File tree

4 files changed

+317
-12
lines changed

4 files changed

+317
-12
lines changed

docs/demo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ More interesting examples actually test database objects. Here is an example tes
8484
* Procedure Test
8585
* Function Test
8686
* Table Constraints Test
87-
* Table Trigger Test
87+
* [Table/View Trigger Test](Trigger-Test.md)
8888
* [Type Test](Type-Test.md)
8989

9090
## utPLSQL 2.3 Examples

docs/demo/Trigger-Test .md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
[Demos and Examples](README.md)
2+
3+
# Test a Table Trigger
4+
5+
---
6+
7+
## Table and View Triggers
8+
9+
What types and kinds?
10+
11+
Other than tables?
12+
13+
## Test a Table Trigger
14+
15+
Create a Table and Trigger.
16+
17+
Run this:
18+
19+
```
20+
create table
21+
22+
create trigger
23+
```
24+
25+
## Create a Simple Test Runner
26+
27+
All test runners are written as a PL/SQL package. A simple package is created first. A DBOUT is also identified.
28+
29+
Run this:
30+
31+
```
32+
create or replace package test_simple_object authid definer
33+
as
34+
procedure wtplsql_run;
35+
end test_simple_object;
36+
/
37+
```
38+
39+
And run this:
40+
41+
```
42+
create or replace package body test_simple_object
43+
as
44+
--% WTPLSQL SET DBOUT "?????????????????:TABLE TRIGGER" %--
45+
procedure wtplsql_run
46+
as
47+
begin
48+
null;
49+
end wtplsql_run;
50+
end test_simple_object;
51+
/
52+
```
53+
54+
## Add Trigger Test Cases
55+
56+
The constructor has 2 basic functions:
57+
* NULL the the minimum value
58+
* Set number of observations to zero
59+
60+
Run this:
61+
62+
```
63+
create or replace package body test_simple_object
64+
as
65+
66+
end test_simple_object;
67+
/
68+
```
69+
70+
Check the results of the
71+
72+
Run this:
73+
74+
```
75+
set serveroutput on size unlimited format word_wrapped
76+
77+
begin
78+
wtplsql.test_run('????????????????');
79+
wt_text_report.dbms_out(USER,'??????????????',30);
80+
end;
81+
/
82+
```
83+
84+
And Get This:
85+
86+
```
87+
88+
```
89+
90+
This is report level 30, the most detailed level of reporting. Starting from the top, we find the test runner executed .
91+
92+
93+
## Testing View/Other Triggers
94+
95+
96+
---
97+
[Demos and Examples](README.md)

docs/demo/Type-Test.md

Lines changed: 135 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@
55
---
66

77
## PL/SQL Types
8-
* Attributes
9-
* VArray
10-
* Nested Table
8+
9+
Following are the 4 Oracle Types. For the purposes of wtPLSQL Examples, only Object Types will be tested, specifically type methods.
10+
* Collection of Attributes
11+
* VArray Collection
12+
* Nested Table Collection
1113
* Object
1214

1315
## Test a PL/SQL Object Type
1416

15-
Create a simple object type to test.
17+
Create a simple object type to test. This object tracks the minimum value of one or more observations. It also tracks the number of observations. The constructor initializes the object as required.
1618

1719
Run this:
1820

1921
```
2022
create or replace type simple_test_obj_type authid definer
2123
as object
22-
(l_minimum number
23-
,l_observations number
24+
(minimum_value number
25+
,observations number
2426
,CONSTRUCTOR FUNCTION simple_test_obj_type
2527
(SELF IN OUT NOCOPY simple_test_obj_type)
2628
return self as result
@@ -40,22 +42,144 @@ create or replace type body simple_test_obj_type is
4042
return self as result
4143
is
4244
begin
43-
l_minimum := null;
44-
l_observations := 0;
45+
minimum_value := null;
46+
observations := 0;
4547
return;
4648
end simple_test_obj_type;
4749
member procedure add_observation
4850
(SELF IN OUT NOCOPY simple_test_obj_type
4951
,in_observation number)
5052
is
5153
begin
52-
If l_minimum is null then l_minimum := in_observation;
53-
else l_minimum := least(l_minimum, in_observation);
54+
If minimum_value is null then minimum_value := in_observation;
55+
else minimum_value := least(minimum_value, in_observation);
5456
end if;
55-
l_observations := l_observations + 1;
57+
observations := observations + 1;
5658
end add_observation;
5759
end;
60+
/
61+
```
62+
63+
## Create a Simple Test Runner
64+
65+
All test runners are written as a PL/SQL package. A simple package is created first. A DBOUT is also identified.
66+
67+
Run this:
68+
69+
```
70+
create or replace package test_simple_object authid definer
71+
as
72+
procedure wtplsql_run;
73+
end test_simple_object;
74+
/
75+
```
76+
77+
And run this:
78+
79+
```
80+
create or replace package body test_simple_object
81+
as
82+
--% WTPLSQL SET DBOUT "SIMPLE_TEST_OBJ_TYPE:TYPE BODY" %--
83+
procedure wtplsql_run
84+
as
85+
begin
86+
null;
87+
end wtplsql_run;
88+
end test_simple_object;
89+
/
90+
```
91+
92+
## Add Constructor Test Cases
93+
94+
The constructor has 2 basic functions:
95+
* NULL the the minimum value
96+
* Set number of observations to zero
97+
98+
Run this:
99+
58100
```
101+
create or replace package body test_simple_object
102+
as
103+
--% WTPLSQL SET DBOUT "SIMPLE_TEST_OBJ_TYPE:TYPE BODY" %--
104+
procedure t_constructor
105+
is
106+
simple_test_obj simple_test_obj_type;
107+
begin
108+
wt_assert.g_testcase := 'Constructor Happy Path 1';
109+
simple_test_obj := simple_test_obj_type();
110+
wt_assert.isnull(msg_in => 'Object MINIMUM_VALUE'
111+
,check_this_in => simple_test_obj.MINIMUM_VALUE);
112+
wt_assert.eq(msg_in => 'Object OBSERVATIONS'
113+
,check_this_in => simple_test_obj.OBSERVATIONS
114+
,against_this_in => 0);
115+
end t_constructor;
116+
procedure wtplsql_run
117+
as
118+
begin
119+
t_constructor;
120+
end wtplsql_run;
121+
end test_simple_object;
122+
/
123+
```
124+
125+
Check the results of the
126+
127+
Run this:
128+
129+
```
130+
set serveroutput on size unlimited format word_wrapped
131+
132+
begin
133+
wtplsql.test_run('TEST_SIMPLE_OBJECT');
134+
wt_text_report.dbms_out(USER,'TEST_SIMPLE_OBJECT',30);
135+
end;
136+
/
137+
```
138+
139+
And Get This:
140+
141+
```
142+
wtPLSQL 1.1.0 - Run ID 56: 18-Jun-2018 10:04:32 PM
143+
144+
Test Results for WTP.TEST_SIMPLE_OBJECT
145+
Total Test Cases: 1 Total Assertions: 2
146+
Minimum Interval msec: 8 Failed Assertions: 0
147+
Average Interval msec: 74 Error Assertions: 0
148+
Maximum Interval msec: 139 Test Yield: 100.00%
149+
Total Run Time (sec): 0.1
150+
151+
Code Coverage for TYPE BODY WTP.SIMPLE_TEST_OBJ_TYPE
152+
Ignored Lines: 0 Total Profiled Lines: 10
153+
Excluded Lines: 1 Total Executed Lines: 4
154+
Minimum LineExec usec: 0 Not Executed Lines: 4
155+
Average LineExec usec: 1 Unknown Lines: 1
156+
Maximum LineExec usec: 2 Code Coverage: 50.00%
157+
Trigger Source Offset: 0
158+
159+
- WTP.TEST_SIMPLE_OBJECT Test Result Details (Test Run ID 56)
160+
-----------------------------------------------------------
161+
---- Test Case: Constructor Happy Path 1
162+
PASS 139ms Object MINIMUM_VALUE. ISNULL - Expected NULL and got ""
163+
PASS 8ms Object OBSERVATIONS. EQ - Expected "0" and got "0"
164+
165+
- WTP.SIMPLE_TEST_OBJ_TYPE TYPE BODY Code Coverage Details (Test Run ID 56)
166+
Source TotTime MinTime MaxTime
167+
Line Stat Occurs (usec) (usec) (usec) Text
168+
------ ---- ------ --------- ------- --------- ------------
169+
2 UNKN 0 2 2 2 CONSTRUCTOR FUNCTION simple_test_obj_type
170+
7 EXEC 1 1 1 1 minimum_value := null;
171+
8 EXEC 1 0 0 0 observations := 0;
172+
9 EXEC 1 2 2 2 return;
173+
10 EXEC 1 2 2 2 end simple_test_obj_type;
174+
11#NOTX# 0 0 0 0 member procedure add_observation
175+
16#NOTX# 0 0 0 0 If minimum_value is null then minimum_value := in_observation;
176+
17#NOTX# 0 0 0 0 else minimum_value := least(minimum_value, in_observation);
177+
19#NOTX# 0 0 0 0 observations := observations + 1;
178+
20 EXCL 0 0 0 0 end add_observation;
179+
```
180+
181+
This is report level 30, the most detailed level of reporting. Starting from the top, we find the test runner executed 1 test case, 2 assertions, and no failed assertions, which resulted in 100% yield (all tests passed). The next section shows the type body tested had 10 lines profiled, 4 were executed, and 4 were not executed, which resulted in a code coverage of 50%. Additional testing is required to achieve 100% code coverage. For brevity, this additional testing will not be included.
182+
59183

60184
## Testing Private Object Methods and Self-Testing
61185

src/demo/Type-Test.sql

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
create or replace type simple_test_obj_type authid definer
3+
as object
4+
(minimum_value number
5+
,observations number
6+
,CONSTRUCTOR FUNCTION simple_test_obj_type
7+
(SELF IN OUT NOCOPY simple_test_obj_type)
8+
return self as result
9+
,member procedure add_observation
10+
(SELF IN OUT NOCOPY simple_test_obj_type
11+
,in_observation number)
12+
);
13+
/
14+
15+
create or replace type body simple_test_obj_type is
16+
CONSTRUCTOR FUNCTION simple_test_obj_type
17+
(SELF IN OUT NOCOPY simple_test_obj_type)
18+
return self as result
19+
is
20+
begin
21+
minimum_value := null;
22+
observations := 0;
23+
return;
24+
end simple_test_obj_type;
25+
member procedure add_observation
26+
(SELF IN OUT NOCOPY simple_test_obj_type
27+
,in_observation number)
28+
is
29+
begin
30+
If minimum_value is null then minimum_value := in_observation;
31+
else minimum_value := least(minimum_value, in_observation);
32+
end if;
33+
observations := observations + 1;
34+
end add_observation;
35+
end;
36+
/
37+
38+
create or replace package test_simple_object authid definer
39+
as
40+
procedure wtplsql_run;
41+
end test_simple_object;
42+
/
43+
44+
create or replace package body test_simple_object
45+
as
46+
--% WTPLSQL SET DBOUT "SIMPLE_TEST_OBJ_TYPE:TYPE BODY" %--
47+
procedure wtplsql_run
48+
as
49+
begin
50+
null;
51+
end wtplsql_run;
52+
end test_simple_object;
53+
/
54+
55+
create or replace package body test_simple_object
56+
as
57+
--% WTPLSQL SET DBOUT "SIMPLE_TEST_OBJ_TYPE:TYPE BODY" %--
58+
procedure t_constructor
59+
is
60+
simple_test_obj simple_test_obj_type;
61+
begin
62+
wt_assert.g_testcase := 'Constructor Happy Path 1';
63+
simple_test_obj := simple_test_obj_type();
64+
wt_assert.isnull(msg_in => 'Object MINIMUM_VALUE'
65+
,check_this_in => simple_test_obj.MINIMUM_VALUE);
66+
wt_assert.eq(msg_in => 'Object OBSERVATIONS'
67+
,check_this_in => simple_test_obj.OBSERVATIONS
68+
,against_this_in => 0);
69+
end t_constructor;
70+
procedure wtplsql_run
71+
as
72+
begin
73+
t_constructor;
74+
end wtplsql_run;
75+
end test_simple_object;
76+
/
77+
78+
set serveroutput on size unlimited format word_wrapped
79+
80+
begin
81+
wtplsql.test_run('TEST_SIMPLE_OBJECT');
82+
wt_text_report.dbms_out(USER,'TEST_SIMPLE_OBJECT',30);
83+
end;
84+
/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy