I have decided to start using unit testing in PL/SQL, since it could be fun and improve the quality of the code.
So, Ive read several resources available and picked SQL Developer and its unit testing capabilities.
I ran into a stupid problem, and Google failed me.
I’m unit testing a simple package.
--Package spec
CREATE OR REPLACE
PACKAGE SAMPLE_TEST
AS
TYPE SAMPLE_RECORD
IS
RECORD
(
SAMPLE_NUMBER NUMBER(3),
SAMPLE_DATE DATE,
SAMPLE_INTEGER INTEGER );
PROCEDURE DO_SOMETHING(
P_FILE VARCHAR2,
P_RESULT OUT SAMPLE_RECORD);
--OR FUNCTION (..) RETURN SAMPLE_RECORD...
END SAMPLE_TEST;
With the implementation:
--Package body
CREATE OR REPLACE
PACKAGE BODY SAMPLE_TEST
AS
PROCEDURE SAMPLE_PROC(
P_FILE VARCHAR2,
P_RESULT OUT SAMPLE_RECORD)
AS
BEGIN
P_RESULT.SAMPLE_NUMBER := SUBSTR(P_FILE, 0 ,3);
P_RESULT.SAMPLE_DATE := TO_DATE(SUBSTR(P_FILE, 4 ,8), 'DD.MM.RRRR');
P_RESULT.SAMPLE_INTEGER := SUBSTR(P_FILE, 20);
END SAMPLE_PROC;
END SAMPLE_TEST;
The input string is 035200220122102201213.
The result is – an ERROR. Assertion failed.
The procedure is correct, it returns the correct values, but the “unit testing framework” informs me:
P_RESULT : Expected: [<SAMPLE_NUMBER=35, SAMPLE_DATE=20.02.12, SAMPLE_INTEGER=13>],
Received: [<SAMPLE_NUMBER=35, SAMPLE_DATE=20.02.12, SAMPLE_INTEGER=13>]
I can’t find a submited bug anywhere – metalink, Google – any ideas?
this page https://forums.oracle.com/forums/thread.jspa?threadID=2382730
says there is a problem with ref cursors and unit testing…
maybe its related.