-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathutconfig.html
More file actions
636 lines (528 loc) · 22 KB
/
Copy pathutconfig.html
File metadata and controls
636 lines (528 loc) · 22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- WARNING! This file is generated. -->
<!-- To alter documentation, edit files in src directory -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>utConfig Package</title>
<link rel="stylesheet" href="utplsql.css" type="text/css" />
<meta name="keywords" content="utPLSQL, PL\SQL, Unit Testing, Framework, Oracle" />
<meta name="description" content="Unit Testing PL\SQL" />
<meta name="title" content="utConfig Package" />
<meta name="author" content="Steven Feuerstein, Chris Rimmer, Patrick Barel and the utPLSQL Project" />
<meta name="copyright" content="(C) 2000-2005, 2014-2016 Steven Feuerstein, Chris Rimmer, Patrick Barel and the utPLSQL Project" />
</head>
<body>
<div class="purple_bar"><a href="index.html"><img src="utplsql.jpg" alt="utPLSQL logo" /></a></div>
<p>[ <a href="index.html">Home</a>
| <a href="started.html">Getting Started</a>
| <a href="buildpack.html">Build Test Packages</a>
| <a href="examples.html">Examples</a>
| <a href="userguide.html">User Guide</a>
| <a href="release.html">Release Notes</a>
| <a href="map.html">Document Map</a> ]</p>
<p><a href="utplsql.html">< Previous Section: utPLSQL Package</a> | <a href="utresult.html">Next Section: utResult Package ></a></p>
<!-- Begin utPLSQL Body -->
<!-- $Id$ -->
<h1>utConfig Package</h1>
<p>This package contains the following functions and procedures:</p>
<table cellspacing="5">
<tr>
<td><a href="#Whoseconfig">utConfig.tester</a></td>
<td><a href="#Whoseconfig">Return whose configuration is used</a></td>
</tr>
<tr>
<td><a href="#setconfig">utConfig.settester</a></td>
<td><a href="#setconfig">Set whose configuration is used</a></td>
</tr>
<tr>
<td><a href="utconfig.html#Showconfig">utConfig.showconfig</a></td>
<td><a href="utconfig.html#Showconfig">View a schema's configuration</a></td>
</tr>
<tr>
<td><a href="#Setdir">utConfig.setdir</a></td>
<td><a href="#Setdir">Set the directory containing the test package code</a></td>
</tr>
<tr>
<td><a href="#dir">utConfig.dir</a></td>
<td><a href="#dir">Return the directory containing the test package code</a></td>
</tr>
<tr>
<td><a href="#Setprefix">utConfig.setprefix</a></td>
<td><a href="#Setprefix">Set the default unit test prefix for your code</a></td>
</tr>
<tr>
<td><a href="#prefix">utConfig.prefix</a></td>
<td><a href="#prefix">Return the default unit test prefix for your code</a></td>
</tr>
<tr>
<td><a href="#Manualregister">utConfig.registertest</a></td>
<td><a href="#Manualregister">Set the registration mode (manual or automatic)</a></td>
</tr>
<tr>
<td><a href="#Manualregister">utConfig.registering</a></td>
<td><a href="#Manualregister">Return the registration mode</a></td>
</tr>
<tr>
<td><a href="#Autocompile">utConfig.autocompile</a></td>
<td><a href="#Autocompile">Set autocompile feature</a></td>
</tr>
<tr>
<td><a href="#Autocompile">utConfig.autocompiling</a></td>
<td><a href="#Autocompile">Return the autocompile flag</a></td>
</tr>
<tr>
<td><a href="#Delimiter">utConfig.setdelimiter</a></td>
<td><a href="#Delimiter">Set the V2 delimiter</a></td>
</tr>
<tr>
<td><a href="#Delimiter">utConfig.delimiter</a></td>
<td><a href="#Delimiter">Return the V2 delimiter</a></td>
</tr>
<tr>
<td><a href="#ShowFailuresOnly">utConfig.showfailuresonly</a></td>
<td><a href="#ShowFailuresOnly">Turn off the display of successful tests</a></td>
</tr>
<tr>
<td><a href="#ShowFailuresOnly">utConfig.showingfailuresonly</a></td>
<td><a href="#ShowFailuresOnly">Return whether successful test results are shown or not</a></td>
</tr>
<tr>
<td><a href="#setgetreporter">utConfig.setreporter</a></td>
<td><a href="#setgetreporter">Sets the default Output Reporter to use</a></td>
</tr>
<tr>
<td><a href="#setgetreporter">utConfig.getreporter</a></td>
<td><a href="#setgetreporter">Gets the name of the default Output Reporter to use</a></td>
</tr>
<tr>
<td><a href="fileout.html#setfiledir">utConfig.setfiledir</a></td>
<td><a href="fileout.html#setfiledir">Set the directory for file output</a></td>
</tr>
<tr>
<td><a href="fileout.html#setfiledir">utConfig.filedir</a></td>
<td><a href="fileout.html#setfiledir">Return which directory is used for file output</a></td>
</tr>
<tr>
<td><a href="fileout.html#filename1">utConfig.setuserprefix</a></td>
<td><a href="fileout.html#filename1">Set the user prefix for output file names</a></td>
</tr>
<tr>
<td><a href="fileout.html#filename1">utConfig.userprefix</a></td>
<td><a href="fileout.html#filename1">Return the user prefix for output file names</a></td>
</tr>
<tr>
<td><a href="fileout.html#filename2">utConfig.setincludeprogname</a></td>
<td><a href="fileout.html#filename2">Set whether to include the name of the program being tested in output file names</a></td>
</tr>
<tr>
<td><a href="fileout.html#filename2">utConfig.includeprogname</a></td>
<td><a href="fileout.html#filename2">Return whether to include the name of the program being tested in output file names</a></td>
</tr>
<tr>
<td><a href="fileout.html#filename3">utConfig.setdateformat</a></td>
<td><a href="fileout.html#filename3">Set the date format for the date portion of output file names</a></td>
</tr>
<tr>
<td><a href="fileout.html#filename3">utConfig.dateformat</a></td>
<td><a href="fileout.html#filename3">Return the date format used to construct output file names</a></td>
</tr>
<tr>
<td><a href="fileout.html#filename4">utConfig.setfileextension</a></td>
<td><a href="fileout.html#filename4">Set the file extension for output file names</a></td>
</tr>
<tr>
<td><a href="fileout.html#filename4">utConfig.fileextension</a></td>
<td><a href="fileout.html#filename4">Return the file extension used for output file names</a></td>
</tr>
<tr>
<td><a href="fileout.html#allinone">utConfig.setfileinfo</a></td>
<td><a href="fileout.html#allinone">Set all of the above file output related items</a></td>
</tr>
<tr>
<td><a href="fileout.html#allinone">utConfig.fileinfo</a></td>
<td><a href="fileout.html#allinone">Return all of the above file output related items</a></td>
</tr>
</table>
<p>
To make it as easy as possible for you to run your tests, utPLSQL stores
various pieces of configuration data in the ut_config table. This data
is stored by schema name and is automatically loaded into utPLSQL the first
time you use this utility in your session. This configuration information
is also automatically updated whenever you call utPLSQL.test -- or any
of the utPLSQL programs specifically designed to change the configuration
settings.
</p>
<p>
You can at any time view the utPLSQL configuration for the currently-connected
schema or for another schema (there is not at this point any schema-level
security; all utPLSQL users can view the configurations of all other users).
</p>
<p>The data that is currently maintained for a utPLSQL user are:</p>
<p>
<b>Test package directory</b> - the location of the test package code
you want to run. You must specify a directory in order to allow utPLSQL
to automatically compile your test packages before each test run.
</p>
<p>
<b>Unit test prefix</b> - the prefix used for test package names and
the program names within the package. If you do not specify a prefix, the
default of "ut_" is automatically applied.
</p>
<p>
<b>Unit test registration mod</b>e - This setting determines whether
utPLSQL will automatically identify the unit tests to be run (strongly
recommended) or if you have chosen to manually register your unit tests
in the test package setup procedure.
</p>
<p>
<b>Auto-compilation of test packages</b> - By default, utPLSQL will
recompile your test package before execution. You can turn off this feature
and manually recompile only when you desire (a fine idea if your test package
has gotten very large!).
</p>
<h2><a name="Whoseconfig"></a>Return whose configuration is being used</h2>
<p>
By default, the configuration stored for the currently-connected user will
be used. However, it is possible to use configurations stored against
other usernames. To show whose configuration is currently being used
the following function is used:
</p>
<pre>
FUNCTION utConfig.tester RETURN VARCHAR2;
</pre>
<h2><a name="setconfig"></a>Set whose configuration is being used</h2>
<p>
This returns the configuration that will be used whenever a username is
not specified. To set this, the following procedure is used:
</p>
<pre>
PROCEDURE utConfig.settester (username_in IN VARCHAR2 := USER);
</pre>
<h2><a name="Showconfig"></a>View a schema's configuration</h2>
<p>
Call the utconfig.showconfig procedure to view the configuration for a specified
schema. The header is:
</p>
<pre>
PROCEDURE utConfig.showconfig (username_in IN VARCHAR2 := NULL);
</pre>
<p>
If you do not specify a schema, then the <a href="#Whoseconfig">currently
used</a> configuration is returned. Here is an example of output from this
procedure:
</p>
<pre>
SQL> exec utconfig.showconfig
=============================================================
utPLSQL Configuration for SCOTT
Directory: /apps/utplsql/code
Autcompile? Y
Manual test registration? N
Prefix = test_
=============================================================
</pre>
<p>And here is an example of calling showConfig for a different schema:</p>
<pre>
SQL> exec utconfig.showconfig ('COMP')
=============================================================
utPLSQL Configuration for COMP
Directory: M:\shared_apps\utplsql\comp
Autcompile? N
Manual test registration? N
Prefix = ut_
=============================================================
</pre>
<p>
You might want to put a call to showConfig in your SQL*Plus login file
so that you are reminded on startup as to what the current settings are.
Here is such a script (to be found in Examples\login_sample.sql):
</p>
<pre>
exec utconfig.setdir ('e:\openoracle\utplsql\utinstall\examples')
SET SERVEROUTPUT ON SIZE 1000000 FORMAT WRAPPED
exec utconfig.showconfig
</pre>
<h2><a name="Setdir"></a>Set the directory containing the test package code</h2>
<p>
If you want utPLSQL to compile your test package, you must tell it the
directory in which your code is found. You can do this either when you
<a href="defsuite.html">define your test suite</a> and packages within the suite, or you can call the
utConfig.setdir procedure to set the directory for your current session.
</p>
<p>
Note: as of v1.5.1, the value you pass in any of these programs is saved
in the configuration table and will be used in the future -- until you
change it by passing a different value.
</p>
<p>The header for this procedure is:</p>
<pre>
PROCEDURE utConfig.setdir (dir_in IN VARCHAR2, username_in IN VARCHAR2 := NULL);
</pre>
<p>
where dir_in is the directory and username_in is the name of the schema
to which this directory applies (NULL means the <a href="#Whoseconfig">currently
used</a> configuration is set), as in:
</p>
<pre>
SQL> exec utconfig.setdir ('e:\demo\utplsql');
</pre>
<p>or, with the specification of a non-current schema:</p>
<pre>
SQL> exec utconfig.setdir ('e:\demo\utplsql', 'ANALYSIS');
</pre>
<p>Note that this directory must be accessible through UTL_FILE.</p>
<p>
You might consider putting the the call to utConfig.setdir into your
login.sql so that it is run automatically, each time your start up SQL*Plus
-- if you are always working from the same directory.
</p>
<h2><a name="dir"></a>Return the directory containing the test package code</h2>
<p>You can obtain the current directory with a call to utConfig.dir:</p>
<pre>
FUNCTION utConfig.dir (username_in IN VARCHAR2 := NULL)
RETURN VARCHAR2;
</pre>
<h2><a name="Setprefix"></a>Set the default unit test prefix for your code.</h2>
<p>
The unit test prefix is very important in utPLSQL; the utility uses the
prefix to associate source code to be tested with the test package. The
prefix also allows utPLSQL to automatically identify the programs within
a test package that are to be executed as unit tests.
</p>
<p>
The default prefix in utPLSQL is "ut_", but you can override this when
you call utPLSQL.test or by calling the utConfig.setprefix procedure:
</p>
<pre>
PROCEDURE utConfig.setPrefix (
prefix_in IN VARCHAR2, username_in IN VARCHAR2 := NULL)
</pre>
<p>
where prefix_in is the prefix and username_in is the name of the schema
to which this prefix applies (NULL means the <a href="#Whoseconfig">currently
used</a> configuration is set), as in:
</p>
<pre>
SQL> exec utconfig.setPrefix ('tst#');
</pre>
<p>or, with the specification of a non-current schema:</p>
<pre>
SQL> exec utconfig.setPrefix ('t_', 'ANALYSIS');
</pre>
<h2><a name="prefix"></a>Return the default unit test prefix for your code.</h2>
<p>You can obtain the current prefix with a call to utConfig.prefix:</p>
<pre>
FUNCTION utConfig.prefix (username_in IN VARCHAR2 := NULL)
RETURN VARCHAR2;
</pre>
<p>
uPLSQL currently does not support the use of a suffix, or combination of
suffix and prefix, to identify test packages and unit test procedures.
</p>
<h2><a name="Manualregister"></a>Set the registration mode (manual or automatic).</h2>
<p>
As of utPLSQL v1.5.1, you no longer have to register your unit test procedures
in the setup procedure of your test package. Instead, utPLSQL will scan
the data dictionary (via theALL_ARGUMENTS view) for the names of all the
unit test procedures you have defined, and then run them. utPLSQL identifies
these programs by looking for all programs whose names start with the specified
prefix.
</p>
<p>
If you so choose, you can request that utPLSQL turn off automatic detection
of unit test procedures and only run those programs listed in the setup
procedure. To do this, you call the utConfig.registerTest procedure:
</p>
<pre>
PROCEDURE utConfig.registerTest (
onoff_in IN BOOLEAN,
username_in IN VARCHAR2 := NULL
);
</pre>
<p>as in:</p>
<pre>
SQL> exec utConfig.registerTest (TRUE)
</pre>
<p>
Note: if you are using automatic unit test detection, any calls to utPLSQL.addtest
in the setup procedure <i><b>will be ignored</b>.</i>
</p>
<p>You can return the current registration mode using the following function:</p>
<pre>
FUNCTION registeringtest (username_in IN VARCHAR2 := NULL)
RETURN BOOLEAN;
</pre>
<p>This returns TRUE if the registration mode has been set to manual and FALSE otherwise.</p>
<h2><a name="Autocompile"></a>Set autocompile feature</h2>
<p>
The default settings for utPLSQL is to re-compile
your base package before each unit test. This guarantees that any recent
changes will be tested. It also saves you the step of doing an explicit
compile.
</p>
<p>In order to perform automatic compilation:</p>
<ul>
<li>
Your schema will need to
have either CREATE PROCEDURE or CREATE ANY PROCEDURE privileges granted
<i>directly</i>;
you cannot grant these privileges through roles.
</li>
<li>
You will need to set or
pass the location of the source code. You can do this by calling <a href="#Setdir">utConfig.setdir</a>
or by including the directory location in your call to <a href="utplsql.html#utplsql.test">utPLSQL.test</a>
or <a href="utplsql.html#utplsql.testsuite">utPLSQL.testsuite</a> (the dir_in
parameter).
</li>
<li>
The package specification
must be contained in a file named <package>.pks; the body must be stored
in <package>.pkb.
</li>
<li>
You must have configured
the
<a href="admin.html#UTL_FILE">UTL_FILE</a> built-in package for use
on your database instance.
</li>
</ul>
<p>
In general (and the default), you should allow your
test package to be recompiled with each execution. You might want to avoid
recompilation if:
</p>
<ul>
<li>
You have made a copy of the package body with some
temporary changes and already compiled that. If you recompile automatically,
you will wipe out those changes.
</li>
<li>
You have not set up UTL_FILE
and you don't want to deal with it.
</li>
<li>
You are running the tests
on a server to which you have no access other than via a database connection.
</li>
</ul>
<h3>Turning off Auto-compile</h3>
<p>
If you are working with products like SQL*Navigator,
you may be always editing from code stored in the database. In this case,
you will never want to have utPLSQL recompile your code for you - it will
already be compiled and you do not need to hassle with UTL_FILE.
</p>
<p>You can avoid auto-recompilation in two ways:</p>
<p>
1. Pass a value of FALSE for the recompile_in argument
to utPLSQL.test or utPLSQL.testsuite. Here is an example:
</p>
<pre>
BEGIN
-- Define a test suite for PL/Vision
utsuite.add ('PLVision');
-- Add two packages for testing
utsuite.addpkg (
'PLVision', 'PLVstr', dir_in => 'e:\utplsql');
utsuite.addpkg (
'PLVision', 'PLVdate', dir_in => 'e:\utplsql');
-- Run the test suite
utplsql.testsuite (
'PLVision', recompile_in => FALSE);
END;
/</pre>
<p>
If you know that you will <i>never</i> want to recompilation,
however, you can set the default behavior at the schema level by calling
the autocompile procedure
</p>
<pre>
PROCEDURE utConfig.autocompile (
onoff_in IN BOOLEAN,
username_in IN VARCHAR2 := NULL
);
</pre>
<p>
So I can make the following
call to turn off autocompilation for the SCOTT schema:
</p>
<pre>
SQL> exec utconfig.autocompile (FALSE, 'SCOTT')
</pre>
<p>
This program updates the ut_config table with your information and then
commits the setting.
</p>
<p>
You can determine the current
setting for auto-compilation at any time by calling the following function:
</p>
<pre>
FUNCTION utConfig.autocompiling (username_in IN VARCHAR2 := NULL)
RETURN BOOLEAN;
</pre>
<p>
Note: When you set the schema-level recompilation
value to FALSE, that will override anything you pass in a call to utPLSQL.test
or utPLSQL.testsuite.
</p>
<h2><a name="Delimiter"></a>V2 Delimiter</h2>
<p>You can set the delimiter to be used in V2 procedure names using the following procedure:</p>
<pre>
PROCEDURE setdelimiter (
delimiter_in IN VARCHAR2,
username_in IN VARCHAR2 := NULL
);
</pre>
<p>while the current delimiter can be obtained by the function:</p>
<pre>
FUNCTION delimiter (username_in IN VARCHAR2 := NULL)
RETURN VARCHAR2;
</pre>
<h2><a name="ShowFailuresOnly">Turn off the display of successful test results</a></h2>
<p>
By default, the results of all the tests are shown. This includes both successful and unsuccessful
results. The following procedure allows you to limit the tests shown to only those that have failed:
</p>
<pre>
PROCEDURE showfailuresonly (
onoff_in IN BOOLEAN,
username_in IN VARCHAR2 := NULL
);
</pre>
<p>the current setting can be obtained by the function:</p>
<pre>
FUNCTION showingfailuresonly (username_in IN VARCHAR2 := NULL)
RETURN BOOLEAN;
</pre>
<h2><a name="setgetreporter">Set and Get the default output reporter</a></h2>
<p>
By default, all results are sent to the screen via DBMS_OUTPUT. However, it is possible to use other output reporters as described in more detail
on <a href="reporter.html">this page</a>. The following procedure allows you to set which output reporter should be used by default:
</p>
<pre>
PROCEDURE setreporter (
reporter_in IN VARCHAR2
,username_in IN VARCHAR2 := NULL
);
</pre>
<p>as usual, the current setting can be obtain by the following function:</p>
<pre>
FUNCTION getreporter (username_in IN VARCHAR2 := NULL)
RETURN VARCHAR2;
</pre>
<!-- End utPLSQL Body -->
<p><a href="utplsql.html">< Previous Section: utPLSQL Package</a> | <a href="utresult.html">Next Section: utResult Package ></a></p>
<div class="purple_bar"><a href="index.html"><img src="utplsql.jpg" alt="utPLSQL logo" /></a></div>
<p>
<a href="http://validator.w3.org/check?uri=referer">
<img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" />
</a>
</p>
<p class="copyright">Copyright © 2000-2005, 2014-2016 <a href="mailto:steven@stevenfeuerstein.com">Steven Feuerstein</a>, <a href="mailto:c@24.org.uk">Chris Rimmer</a>, <a href="mailto:pbarel@vda.nl">Patrick Barel</a> and the utPLSQL Project. All rights reserved</p>
</body>
</html>