Skip to content

Commit 263f049

Browse files
committed
Finished the Simple Stuff Demos
1 parent 43f4717 commit 263f049

File tree

5 files changed

+117
-27
lines changed

5 files changed

+117
-27
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ These are the working definitions for the wtPLSQL project.
6666

6767
**Testcase** - A logical grouping of assertions to run happy path, decision tree, boundary condition, and/or fault insertion tests. May included one or more setup, teardown, and intermediate setups.
6868

69-
**Test Runner** - A PL/SQL package that exercises a DBOUT and uses assertions to confirm the correct funcionality of the DBOUT. It may have zero or more testcases. It always contains a call to the WTPLSQL.TEST_RUN procedure. It may contain DBOUT annotations and/or "exclude source lines" annotations.
69+
**Test Runner** - A PL/SQL package that exercises a DBOUT and uses assertions to confirm the correct funcionality of the DBOUT. It may have zero or more testcases. It always contains a call to the WTPLSQL.TEST_RUN procedure. It may contain DBOUT annotations and "ignore source lines" annotations.
7070

7171
The [Other Definitions page](Other-Definitions.md) includes definitions from many sources to help define the terms used in various software testing methodologies.
7272

docs/demo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Test results from assertions can be queried from a set of wtPLSQL tables. The ex
1313

1414
The [Simple Stuff](Simple-Stuff.md) page is a confidence builder, excellent for first time users of wtPLSQL.
1515

16-
The [Test Runner](Test-Runner.md) page covers all the basics of creating a Test Runner. wtPLSQL is all about creating and running Test Runners.
16+
The [Test Runner](Test-Runner.md) page covers all the basics of creating a Test Runner package.
1717

1818
## Database Object Tests
1919
More interesting examples actually test database objects. Here is an example test of each database object supported by wtPLSQL.

docs/demo/Simple-Stuff.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[Website Home Page](README.md)
1+
[Demos and Examples](README.md)
22

33
# Simple Stuff
44

@@ -24,19 +24,25 @@ grant create procedure to wtp_demo;
2424
The simplest check for a wtPLSQL installation is to select the "version from dual".
2525

2626
Run this:
27+
2728
```
2829
select wtplsql.show_version from dual;
2930
```
30-
and get this:
31+
32+
And get this:
33+
3134
```
3235
SHOW_VERSION
33-
------------
36+
-----------------------------------------------------------
3437
1.1.0
3538
```
3639

40+
This shows the wtPLSQL version as 1.1.0.
41+
3742
Another simple test is an ad-hoc assertion. This test requires DBMS_OUTPUT. The results of this test are not recorded.
3843

3944
Run this:
45+
4046
```
4147
set serveroutput on size unlimited format word_wrapped
4248
@@ -47,12 +53,20 @@ begin
4753
end;
4854
/
4955
```
56+
5057
And get this:
58+
5159
```
5260
PASS Ad-Hoc Test. EQ - Expected "1" and got "1"
5361
```
5462

63+
This indicates:
64+
* the assertion passed
65+
* the assertion had the message "Ad-Hoc Test"
66+
* the assertion name is "EQ"
67+
* the assertion details which may include the values tested
68+
5569
Note: This ad-hoc test also demonstrates implicit data type conversion.
5670

5771
---
58-
[Website Home Page](README.md)
72+
[Demos and Examples](README.md)

docs/demo/Test-Runner.md

Lines changed: 96 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
---
66
Most all wtPLSQL tests are executed with a Test Runner. A Test Runner is a PL/SQL package written by the tester. Below are examples of very simple Test Runners.
77

8-
Minimal Test Runner Package Spec:
8+
Run this:
9+
910
```
10-
create or replace package simple_test_runner authid current_user
11+
create or replace package simple_test_runner authid definer
1112
as
1213
procedure wtplsql_run;
1314
end simple_test_runner;
1415
/
15-
```
16-
Minimal Test Runner Package Body:
17-
```
16+
1817
create or replace package body simple_test_runner
1918
as
2019
procedure wtplsql_run is begin
@@ -25,19 +24,23 @@ as
2524
end simple_test_runner;
2625
/
2726
```
28-
This is a minimal test runner. It is a package that contains the (public) WTPLSQL_RUN procedure and 1 assertion. It does the same assertion as the ad-hoc assertion in the "Simple Test" page. However, the test results are not sent to DBMS_OUTPUT. The test results are saved in the wtPLSQL tables.
27+
28+
SIMPLE_TEST_RUNNER is a minimal test runner. It is a package that contains the (public) WTPLSQL_RUN procedure and 1 assertion. It does the same assertion as the ad-hoc assertion in the [Simple Test](Simple-Test.md) page.
2929

3030
## Execute and Display
3131

3232
To execute the Test Runner, run this:
33+
3334
```
3435
begin
3536
wtplsql.test_run('SIMPLE_TEST_RUNNER');
3637
end;
3738
/
3839
```
3940

40-
The results for this assertion have been saved in the wtPLSQL tables. Use the default reporting package to display the results.
41+
There are no test results because the test results were not sent to DBMS_OUTPUT. The test results were saved in the wtPLSQL tables.
42+
43+
To view the results, run this:
4144

4245
```
4346
set serveroutput on size unlimited format word_wrapped
@@ -46,23 +49,29 @@ begin
4649
wt_text_report.dbms_out;
4750
end;
4851
/
52+
```
53+
54+
And get this:
4955

56+
```
5057
wtPLSQL 1.1.0 - Run ID 12: 15-Jun-2018 01:45:16 PM
5158
5259
Test Results for WTP_DEMO.SIMPLE_TEST_RUNNER
53-
Total Testcases: 0 Total Assertions: 1
60+
Total Test Cases: 0 Total Assertions: 1
5461
Minimum Interval msec: 56 Failed Assertions: 0
5562
Average Interval msec: 56 Error Assertions: 0
5663
Maximum Interval msec: 56 Test Yield: 100.00%
5764
Total Run Time (sec): 0.2
5865
```
5966

60-
While the results might vary, this is latest test result summary from all Test Runners for the login user. The report confirms that one assertion was executed for SIMPLE_TEST_RUNNER and it passed.
67+
This is latest test result summary from all Test Runners for the login user. The interval time shown here is the elapsed time from starting the Test Runner until the first assertion was executed. The total run time is the elapsed time from start to finish for the Test Runner. The report confirms that one assertion was executed for SIMPLE_TEST_RUNNER and it passed. All tests passed, so the test yield is 100%.
6168

6269
## WT_TEXT_REPORT Display Levels
6370

6471
This example shows all result details for the SIMPLE_TEST_RUNNER only.
6572

73+
Run this:
74+
6675
```
6776
set serveroutput on size unlimited format word_wrapped
6877
@@ -71,11 +80,15 @@ begin
7180
,in_detail_level => 30);
7281
end;
7382
/
83+
```
7484

85+
And get this:
86+
87+
```
7588
wtPLSQL 1.1.0 - Run ID 12: 15-Jun-2018 01:45:16 PM
7689
7790
Test Results for WTP_DEMO.SIMPLE_TEST_RUNNER
78-
Total Testcases: 0 Total Assertions: 1
91+
Total Test Cases: 0 Total Assertions: 1
7992
Minimum Interval msec: 56 Failed Assertions: 0
8093
Average Interval msec: 56 Error Assertions: 0
8194
Maximum Interval msec: 56 Test Yield: 100.00%
@@ -86,38 +99,87 @@ end;
8699
PASS 56ms Ad-Hoc Test. EQ - Expected "1" and got "1"
87100
```
88101

89-
A detail level of 30 shows all summary and detail results for a Test Runner. In this case, the summary is the same and the detailed results of the EQ assertion are shown. These detail levels are explained in the [Reference Page](../Reference.md).
102+
This shows the latest test result summary with test results details. A detail level of 30 shows summary and detailed test results for a Test Runner. In this case, the summary is the same and the detailed results of the EQ assertion are shown. These detail levels are explained in the [Reference Page](../Reference.md).
103+
104+
The detailed results shown are the same as the ad-hoc result, with a "56ms" added. The detailed results from the Test Runner includes the elapsed time between assertions, or elapsed time from Test Runner startup to the first assertion.
90105

91106
## Test Cases
92107

93-
For wtPLSQL, a test case is a collection of assertions. Test results can be grouped by test case name. There can be zero or more test cases in a Test Runner.
108+
For wtPLSQL, a test case is a collection of assertions. Assertion results can be grouped by test case. There can be zero or more test cases in a Test Runner.
109+
110+
Run this:
94111

95112
```
96113
create or replace package body simple_test_runner
97114
as
98115
procedure wtplsql_run is begin
99-
wt_assert.g_testcase := 'My Test Case';
100-
wt_assert.eq(msg_in => 'Ad-Hoc Test'
116+
wt_assert.g_testcase := 'My Test Case A';
117+
wt_assert.eq(msg_in => 'Ad-Hoc Test1'
101118
,check_this_in => 1
102119
,against_this_in => '1');
120+
wt_assert.eq(msg_in => 'Ad-Hoc Test2'
121+
,check_this_in => 2
122+
,against_this_in => '2');
123+
wt_assert.g_testcase := 'My Test Case B';
124+
wt_assert.eq(msg_in => 'Ad-Hoc Test1'
125+
,check_this_in => 4
126+
,against_this_in => ' 4');
127+
wt_assert.eq(msg_in => 'Ad-Hoc Test2'
128+
,check_this_in => 5
129+
,against_this_in => to_number(' 5'));
103130
end wtplsql_run;
104131
end simple_test_runner;
105132
/
106133
```
107134

108-
This modification of the SIMPLE_TEST_RUNNER sets a test case for the assertion. It is done by modifying a WT_ASSERT package variable. More on this below.
135+
Setting a value for WT_ASSERT.G_TESTCASE in the SIMPLE_TEST_RUNNER package sets a test case for all following assertions. This value can be set multiple times within a Test Runner. The results summary will show the number of test cases. The test results details will group assertions by test case.
109136

137+
Run this:
138+
139+
```
140+
begin
141+
wtplsql.test_run('SIMPLE_TEST_RUNNER');
142+
wt_text_report.dbms_out(in_runner_name => 'SIMPLE_TEST_RUNNER'
143+
,in_detail_level => 30);
144+
end;
145+
/
146+
```
147+
148+
And get this:
149+
150+
```
151+
wtPLSQL 1.1.0 - Run ID 43: 16-Jun-2018 07:43:50 AM
152+
153+
Test Results for WTP_DEMO.SIMPLE_TEST_RUNNER
154+
Total Test Cases: 2 Total Assertions: 4
155+
Minimum Interval msec: 0 Failed Assertions: 1
156+
Average Interval msec: 0 Error Assertions: 0
157+
Maximum Interval msec: 1 Test Yield: 75.00%
158+
Total Run Time (sec): 0.0
159+
160+
- WTP_DEMO.SIMPLE_TEST_RUNNER Test Result Details (Test Run ID 43)
161+
-----------------------------------------------------------
162+
---- Test Case: My Test Case A
163+
PASS 1ms Ad-Hoc Test1. EQ - Expected "1" and got "1"
164+
PASS 0ms Ad-Hoc Test2. EQ - Expected "2" and got "2"
165+
---- Test Case: My Test Case B
166+
#FAIL# 0ms Ad-Hoc Test1. EQ - Expected " 4" and got "4"
167+
PASS 0ms Ad-Hoc Test2. EQ - Expected "5" and got "5"
168+
```
169+
170+
The Test Results summary shows 2 test cases were found. The Test Results Details show the assertion results grouped by test case. The details also show a failed assertion. It also shows "Ad-Hoc Test2" in "My Test Case B" passed because the TO_NUMBER was used to remove the space character from " 5".
110171

111172
## DBOUT Annotation
112173

113174
The Database Object Under Test (DBOUT) annotation is used to determine which database object to profile. If this annotation identifies accessible source code for a DBOUT, the DBMS_PROFILER package is activated to check code coverage.
114175

176+
Run this:
177+
115178
```
116179
create or replace package body simple_test_runner
117180
as
118181
--% WTPLSQL SET DBOUT "SIMPLE_TEST_RUNNER:PACKAGE BODY" %--
119182
procedure wtplsql_run is begin
120-
wt_assert.g_testcase := 'My Test Case';
121183
wt_assert.eq(msg_in => 'Ad-Hoc Test'
122184
,check_this_in => 1
123185
,against_this_in => '1');
@@ -128,17 +190,23 @@ end simple_test_runner;
128190

129191
With the addition of the DBOUT annotation, the profiling information is available for the SIMPLE_TEST_RUNNER package.
130192

193+
Run this:
194+
131195
```
132196
begin
133197
wtplsql.test_run('SIMPLE_TEST_RUNNER');
134198
wt_text_report.dbms_out(USER,'SIMPLE_TEST_RUNNER');
135199
end;
136200
/
201+
```
202+
203+
And get this:
137204

205+
```
138206
wtPLSQL 1.1.0 - Run ID 38: 15-Jun-2018 11:03:52 PM
139207
140208
Test Results for WTP_DEMO.SIMPLE_TEST_RUNNER
141-
Total Testcases: 1 Total Assertions: 1
209+
Total Test Cases: 0 Total Assertions: 1
142210
Minimum Interval msec: 186 Failed Assertions: 0
143211
Average Interval msec: 186 Error Assertions: 0
144212
Maximum Interval msec: 186 Test Yield: 100.00%
@@ -153,13 +221,15 @@ end;
153221
Trigger Source Offset: 0
154222
```
155223

156-
Note the addition of the "Code Coverage" Summary. DBMS_PROFILER found 4 lines of significance in the source code. 3 of those lines were executed. 1 line is unknown or undefined by DBMS_PROFILER. Unknown lines consume execution time, but were not executed.
224+
This shows the latest test result summary and code coverage summary for the SIMPLE_TEST_RUNNER test runner. DBMS_PROFILER found 4 lines of significance in the source code. 3 of those lines were executed. 1 line is unknown or undefined by DBMS_PROFILER. Unknown lines consume execution time, but were not executed.
157225

158226
## Ignore Annotation
159227

160228
In the previous example, the SIMPLE_TEST_RUNNER package is both the Test Runner and the Database Object Under Test (DBOUT). In practice, this is a self testing package. Because DBMS_OUTPUT includes all the source lines, there is a need to segregate "testing" source lines from "tested" source lines. The ignore annotation is used to segregate these lines.
161229

162-
The function "add2" represents some code that needs to be tested. It is also a private function. Self testing packages can run private functions.
230+
The function "add2" represents some code that needs to be tested. It is also a private function. Self testing packages can test the private functions in the package.
231+
232+
Run this:
163233

164234
```
165235
create or replace package body simple_test_runner
@@ -185,17 +255,23 @@ The DBOUT annotation has been moved for convenience. It can be placed anywhere
185255

186256
The "begin_ignore" and "end_ignore" annotations have been added to the SIMPLE_TEST_RUNNER package. The intent of these annotations is to ignore the source lines for the WTPLSQL_RUN procedure for code coverage calculations.
187257

258+
Run this:
259+
188260
```
189261
begin
190262
wtplsql.test_run('SIMPLE_TEST_RUNNER');
191263
wt_text_report.dbms_out(USER,'SIMPLE_TEST_RUNNER',50);
192264
end;
193265
/
266+
```
194267

268+
And get this:
269+
270+
```
195271
wtPLSQL 1.1.0 - Run ID 40: 16-Jun-2018 12:38:49 AM
196272
197273
Test Results for WTP_DEMO.SIMPLE_TEST_RUNNER
198-
Total Testcases: 1 Total Assertions: 1
274+
Total Test Cases: 1 Total Assertions: 1
199275
Minimum Interval msec: 111 Failed Assertions: 0
200276
Average Interval msec: 111 Error Assertions: 0
201277
Maximum Interval msec: 111 Test Yield: 100.00%

src/core/wt_text_report.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end p;
2121
procedure result_summary
2222
is
2323
begin
24-
p(' Total Testcases: ' || to_char(nvl(g_test_run_stats_rec.testcases ,0),'9999999') ||
24+
p(' Total Test Cases: ' || to_char(nvl(g_test_run_stats_rec.testcases ,0),'9999999') ||
2525
' Total Assertions: ' || to_char(nvl(g_test_run_stats_rec.asserts ,0),'9999999') );
2626
p(' Minimum Interval msec: ' || to_char(nvl(g_test_run_stats_rec.min_interval_msecs,0),'9999999') ||
2727
' Failed Assertions: ' || to_char(nvl(g_test_run_stats_rec.failures ,0),'9999999') );

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