Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad79d59

Browse files
committed
Added test files
1 parentb5ff144 commitad79d59

File tree

7 files changed

+270
-13
lines changed

7 files changed

+270
-13
lines changed

‎scripts/2_install_demo_project.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
docker run --rm -v$(pwd):/work -w /work/ --network host --entrypoint sqlplus truemark/sqlplus:19.8 \
22
sys/oracle@//127.0.0.1:1521/XE as sysdba @scripts/sql/create_users.sql
33

4-
#docker run --rm -v $(pwd):/work -w /work/ --network host --entrypoint sqlplus truemark/sqlplus:19.8 \
5-
# app/pass@//127.0.0.1:1521/XE @scripts/sql/create_app_objects.sql
6-
#
7-
#docker run --rm -v $(pwd):/work -w /work/ --network host --entrypoint sqlplus truemark/sqlplus:19.8 \
8-
# code_owner/pass@//127.0.0.1:1521/XE @scripts/sql/create_source_owner_objects.sql
9-
#
10-
#docker run --rm -v $(pwd):/work -w /work/ --network host --entrypoint sqlplus truemark/sqlplus:19.8 \
11-
# tests_owner/pass@//127.0.0.1:1521/XE @scripts/sql/create_tests_owner_objects.sql
4+
docker run --rm -v$(pwd):/work -w /work/ --network host --entrypoint sqlplus truemark/sqlplus:19.8 \
5+
app/pass@//127.0.0.1:1521/XE @scripts/sql/create_app_objects.sql
6+
7+
docker run --rm -v$(pwd):/work -w /work/ --network host --entrypoint sqlplus truemark/sqlplus:19.8 \
8+
code_owner/pass@//127.0.0.1:1521/XE @scripts/sql/create_source_owner_objects.sql
9+
10+
docker run --rm -v$(pwd):/work -w /work/ --network host --entrypoint sqlplus truemark/sqlplus:19.8 \
11+
tests_owner/pass@//127.0.0.1:1521/XE @scripts/sql/create_tests_owner_objects.sql

‎scripts/sql/APP.PKG_TEST_ME.pkb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CREATE OR REPLACE PACKAGE BODY PKG_TEST_ME IS
2+
--
3+
-- This
4+
--
5+
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS
6+
BEGIN
7+
IF PPARAM1 IS NULL THEN
8+
RETURN NULL;
9+
ELSIF PPARAM1 = '1' THEN
10+
RETURN 1;
11+
ELSE
12+
RETURN 0;
13+
END IF;
14+
END FC_TEST_ME;
15+
16+
PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS
17+
BEGIN
18+
IF PSNAME IS NULL THEN
19+
NULL;
20+
ELSE
21+
INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME);
22+
COMMIT;
23+
END IF;
24+
END PR_TEST_ME;
25+
26+
END PKG_TEST_ME;
27+
/

‎scripts/sql/APP.PKG_TEST_ME.pks

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--
2+
-- This package is used TO demonstrate the utPL/SQL possibilities
3+
--
4+
CREATE OR REPLACE PACKAGE PKG_TEST_ME AS
5+
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER;
6+
PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2);
7+
END PKG_TEST_ME;
8+
/

‎scripts/sql/APP.TEST_PKG_TEST_ME.pkb

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
CREATE OR REPLACE PACKAGE BODY TEST_PKG_TEST_ME AS
2+
3+
---------------------------------------------------------------------------
4+
PROCEDURE SETUP_GLOBAL IS
5+
BEGIN
6+
-- Put here the code which is valid for all tests and that should be
7+
-- executed once.
8+
NULL;
9+
END SETUP_GLOBAL;
10+
11+
---------------------------------------------------------------------------
12+
PROCEDURE TEARDOWN_GLOBAL IS
13+
BEGIN
14+
-- Put here the code that should be called only once after all the test
15+
-- have executed
16+
NULL;
17+
END TEARDOWN_GLOBAL;
18+
19+
---------------------------------------------------------------------------
20+
PROCEDURE SETUP_TEST IS
21+
BEGIN
22+
-- Nothing to clean up globally
23+
NULL;
24+
END SETUP_TEST;
25+
26+
PROCEDURE TEARDOWN_TEST IS
27+
BEGIN
28+
-- Nothing to clean up globally
29+
NULL;
30+
END TEARDOWN_TEST;
31+
32+
PROCEDURE TEST_FC_INPUT_1 IS
33+
BEGIN
34+
-- Ok this is a real test where I check that the function return 1
35+
-- when called with a '1' parameter
36+
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('1')).TO_EQUAL(1);
37+
END;
38+
39+
PROCEDURE SETUP_TEST_FC_INPUT_1 IS
40+
BEGIN
41+
-- Nothing to be done really
42+
NULL;
43+
END;
44+
45+
PROCEDURE TEARDOWN_TEST_FC_INPUT_1 IS
46+
BEGIN
47+
-- Nothing to be done really
48+
NULL;
49+
END;
50+
51+
PROCEDURE TEST_FC_INPUT_0 IS
52+
BEGIN
53+
-- Ok this is a real test where I check that the function return 0
54+
-- when called with a '0' parameter
55+
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('0')).TO_EQUAL(0);
56+
END;
57+
58+
PROCEDURE TEST_FC_INPUT_NULL IS
59+
BEGIN
60+
-- Ok I check that the function return NULL
61+
-- when called with a NULL parameter
62+
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME(NULL)).TO_BE_NULL;
63+
END TEST_FC_INPUT_NULL;
64+
65+
PROCEDURE TEST_PR_TEST_ME_NULL IS
66+
VNCOUNT1 PLS_INTEGER;
67+
VNCOUNT2 PLS_INTEGER;
68+
BEGIN
69+
-- In this example I check that the procedure does
70+
-- not insert anything when passing it a NULL parameter
71+
SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME;
72+
PKG_TEST_ME.PR_TEST_ME(NULL);
73+
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME;
74+
UT.EXPECT(VNCOUNT1).TO_EQUAL(VNCOUNT2);
75+
END;
76+
77+
PROCEDURE TEST_PR_TEST_ME_NOT_NULL IS
78+
VNCOUNT1 PLS_INTEGER;
79+
VNCOUNT2 PLS_INTEGER;
80+
VSNAME TO_TEST_ME.SNAME%TYPE;
81+
BEGIN
82+
-- In this test I will check that I do insert a value
83+
-- when the parameter is not null. I futher check that
84+
-- the procedure has inserted the value I specified.
85+
SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME;
86+
VSNAME := TO_CHAR(VNCOUNT1);
87+
PKG_TEST_ME.PR_TEST_ME(VSNAME);
88+
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME;
89+
90+
-- Check that I have inserted the value
91+
UT.EXPECT(VNCOUNT1 + 1).TO_EQUAL(VNCOUNT2);
92+
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME T WHERE T.SNAME = VSNAME;
93+
94+
-- Check that I inserted the one I said I would insert
95+
UT.EXPECT(VNCOUNT2).TO_EQUAL(1);
96+
DELETE FROM TO_TEST_ME T WHERE T.SNAME = VSNAME;
97+
COMMIT;
98+
END;
99+
100+
PROCEDURE TEST_PR_TEST_ME_EXISTS IS
101+
BEGIN
102+
-- In case the value exists the procedure should fail with an exception.
103+
BEGIN
104+
PKG_TEST_ME.PR_TEST_ME('EXISTS');
105+
PKG_TEST_ME.PR_TEST_ME('EXISTS');
106+
EXCEPTION
107+
WHEN OTHERS THEN
108+
UT.FAIL('Unexpected exception raised');
109+
END;
110+
END;
111+
112+
PROCEDURE TEST_PR_TEST_ME_CURSOR IS
113+
TYPE REF_CURSOR IS REF CURSOR;
114+
VEXPECTED REF_CURSOR;
115+
VACTUAL REF_CURSOR;
116+
BEGIN
117+
EXECUTE IMMEDIATE 'TRUNCATE TABLE TO_TEST_ME';
118+
OPEN VEXPECTED FOR
119+
SELECT T.SNAME FROM TO_TEST_ME T;
120+
OPEN VACTUAL FOR
121+
SELECT T.SNAME FROM TO_TEST_ME T;
122+
UT.EXPECT(VEXPECTED).TO_(EQUAL(VACTUAL));
123+
END;
124+
125+
END;
126+
/

‎scripts/sql/APP.TEST_PKG_TEST_ME.pks

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS
2+
-- %suite(TEST_PKG_TEST_ME)
3+
-- %suitepath(plsql.examples)
4+
--
5+
-- This package shows all the possibilities to unit test
6+
-- your PL/SQL package. NOTE that it is not limited to
7+
-- testing your package. You can do that on all your
8+
-- procedure/functions...
9+
--
10+
11+
/**
12+
* This two parameters are used by the test framework in
13+
* order to identify the test suite to run
14+
*/
15+
16+
/*
17+
* This method is invoked once before any other method.
18+
* It should contain all the setup code that is relevant
19+
* for all your test. It might be inserting a register,
20+
* creating a type, etc...
21+
*/
22+
-- %beforeall
23+
PROCEDURE SETUP_GLOBAL;
24+
25+
/*
26+
* This method is invoked once after all other method.
27+
* It can be used to clean up all the resources that
28+
* you created in your script
29+
*/
30+
-- %afterall
31+
PROCEDURE TEARDOWN_GLOBAL;
32+
33+
/*
34+
* This method is called once before each test.
35+
*/
36+
-- %beforeeach
37+
PROCEDURE SETUP_TEST;
38+
39+
/*
40+
* This method is called once after each test.
41+
*/
42+
-- %aftereach
43+
PROCEDURE TEARDOWN_TEST;
44+
45+
/**
46+
* This is a real test. The main test can declare a setup
47+
* and teardown method in order to setup and cleanup things
48+
* for that specific test.
49+
*/
50+
-- %test
51+
-- %displayname(Checking if function ('1') returns 1)
52+
-- %beforetest(SETUP_TEST_FC_INPUT_1)
53+
-- %aftertest(TEARDOWN_TEST_FC_INPUT_1)
54+
PROCEDURE TEST_FC_INPUT_1;
55+
PROCEDURE SETUP_TEST_FC_INPUT_1;
56+
PROCEDURE TEARDOWN_TEST_FC_INPUT_1;
57+
58+
-- %test
59+
-- %displayname(Checking if function ('0') returns 0)
60+
PROCEDURE TEST_FC_INPUT_0;
61+
62+
-- %test
63+
-- %displayname(Checking if function (NULL) returns NULL)
64+
PROCEDURE TEST_FC_INPUT_NULL;
65+
66+
-- %test
67+
-- %displayname(Checking if procedure (NULL) insert)
68+
PROCEDURE TEST_PR_TEST_ME_NULL;
69+
70+
-- %test
71+
-- %displayname(Checking if procedure (NOT NULL) insert)
72+
-- %rollback(manual)
73+
PROCEDURE TEST_PR_TEST_ME_NOT_NULL;
74+
75+
-- %test
76+
-- %displayname(Checking if procedure (NOT NULL) insert while existing)
77+
-- %rollback(manual)
78+
-- %tags(exists)
79+
PROCEDURE TEST_PR_TEST_ME_EXISTS;
80+
81+
-- %test
82+
-- %displayname(Demonstrating the use of cursor)
83+
-- %rollback(manual)
84+
-- %tags(cursor)
85+
PROCEDURE TEST_PR_TEST_ME_CURSOR;
86+
87+
END;
88+
/

‎scripts/sql/TO_TEST_ME.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--
2+
-- This is a table used to demonstrate the UNIT test framework.
3+
--
4+
CREATETABLETO_TEST_ME
5+
(
6+
SNAMEVARCHAR2(10)
7+
)
8+
/

‎scripts/sql/create_app_objects.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
whenever sqlerror exit failurerollback
22
whenever oserror exit failurerollback
33

4-
@src/test/resources-its/org/utplsql/maven/plugin/UtPlsqlMojoIT/simple/scripts/sources/TO_TEST_ME.sql
5-
@src/test/resources-its/org/utplsql/maven/plugin/UtPlsqlMojoIT/simple/scripts/sources/APP.PKG_TEST_ME.pks
6-
@src/test/resources-its/org/utplsql/maven/plugin/UtPlsqlMojoIT/simple/scripts/sources/APP.PKG_TEST_ME.pkb
4+
@scripts/sql/TO_TEST_ME.sql
5+
@scripts/sql/APP.PKG_TEST_ME.pks
6+
@scripts/sql/APP.PKG_TEST_ME.pkb
77

8-
@src/test/resources-its/org/utplsql/maven/plugin/UtPlsqlMojoIT/simple/scripts/tests/APP.TEST_PKG_TEST_ME.pks
9-
@src/test/resources-its/org/utplsql/maven/plugin/UtPlsqlMojoIT/simple/scripts/tests/APP.TEST_PKG_TEST_ME.pkb
8+
@scripts/sql/APP.TEST_PKG_TEST_ME.pks
9+
@scripts/sql/APP.TEST_PKG_TEST_ME.pkb

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp