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
There are many kinds of triggers. All of them use PL/SQL to define actions taken when the the trigger is activated.
7
+
The syntax diagram in Oracle's "Database SQL Language Reference" (11.2) gives the list of [constraints](https://docs.oracle.com/cd/E11882_01/server.112/e41084/clauses002.htm#CJAEDFIB) this way:
9
8
10
-
The "Database PL/SQL Language Reference" (11.2) [groups triggers](https://docs.oracle.com/cd/E11882_01/appdev.112/e25519/create_trigger.htm#BABBJHHG) this way:
Typical unit testing (or white box testing) does not include the testing of constraints. In large part, these constraints are assumed to work without testing. Confirmation of continued function of these constraints is a reason to test them.
For brevity, the check constraint will be the only constraint tested.
133
34
134
-
## Create a Simple Test Runner
35
+
## Test Runner
135
36
136
-
All test runners are written as a PL/SQL package. A simple package is created first. A DBOUT is also identified.
37
+
Create a simple test runner.
137
38
138
39
Run this:
139
40
140
41
```
141
-
create or replace package trigger_test_pkg authid definer
42
+
create or replace package table_test_pkg authid definer
142
43
as
143
44
procedure wtplsql_run;
144
-
end trigger_test_pkg;
45
+
end table_test_pkg;
145
46
/
146
47
```
147
48
148
-
And run this:
149
-
150
-
```
151
-
create or replace package body trigger_test_pkg
152
-
as
153
-
--% WTPLSQL SET DBOUT "TRIGGER_TEST_BIR:TRIGGER" %--
154
-
procedure wtplsql_run
155
-
as
156
-
begin
157
-
null;
158
-
end wtplsql_run;
159
-
end trigger_test_pkg;
160
-
/
161
-
```
162
-
163
-
## Add a Trigger Test Case
164
-
165
-
The trigger being tested is a table DML trigger. Testing of a table trigger like this requires a modification of the data in the table. The consequences of leaving this modified data after the test must be considered. In this test, the data modification will not be preserved.
49
+
The constraint being tested ensures the name is in upper case. Testing of the constraint requires a modification of the data in the table. The consequences of leaving this modified data after the test must be considered. In this test, the data modification will not be preserved.
This is report level 30, the most detailed level of reporting. Starting from the top, we find the test runner executed 1 test case and 3 assertions. All tests passed for a 100% yield. The code coverage for the trigger shows 5 profiles, 4 executed, and a code coverage of 100%. Notice the trigger offset of 3 which aligns the source code with the profiled lines.
115
+
This is report level 30, the most detailed level of reporting. Starting from the top, we find the test runner executed 1 test case and 2 assertions. All tests passed for a 100% yield. There is no code coverage for the constraints.
116
+
117
+
This is not a complete test. More test cases are needed to confirm other constraints and sad path .
Copy file name to clipboardExpand all lines: docs/demo/Trigger-Test.md
+15-27Lines changed: 15 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
---
6
6
7
7
## Triggers
8
-
There are many kinds of triggers. All of them use PL/SQL to define actions taken when the the trigger is activated.
8
+
There are many kinds of triggers. All of them use PL/SQL to define actions taken when the trigger is activated.
9
9
10
10
The "Database PL/SQL Language Reference" (11.2) [groups triggers](https://docs.oracle.com/cd/E11882_01/appdev.112/e25519/create_trigger.htm#BABBJHHG) this way:
11
11
* Simple DML Trigger
@@ -15,11 +15,11 @@ The "Database PL/SQL Language Reference" (11.2) [groups triggers](https://docs.o
--% WTPLSQL SET DBOUT "TRIGGER_TEST_BIR:TRIGGER" %--
123
-
procedure wtplsql_run
124
-
as
125
-
begin
126
-
null;
127
-
end wtplsql_run;
128
-
end trigger_test_pkg;
129
-
/
130
-
```
131
-
132
-
## Add a Trigger Test Case
133
-
134
120
The trigger being tested is a table DML trigger. Testing of a table trigger like this requires a modification of the data in the table. The consequences of leaving this modified data after the test must be considered. In this test, the data modification will not be preserved.
This is report level 30, the most detailed level of reporting. Starting from the top, we find the test runner executed 1 test case and 3 assertions. All tests passed for a 100% yield. The code coverage for the trigger shows 5 profiles, 4 executed, and a code coverage of 100%. Notice the trigger offset of 3 which aligns the source code with the profiled lines.
227
213
214
+
This is not a complete test. More test cases are needed to confirm various values are handled correctly when inserted.
0 commit comments