SQL 开发人员单元测试错误?

发布于 2025-01-07 18:07:09 字数 1264 浏览 0 评论 0原文

我决定开始在 PL/SQL 中使用单元测试,因为它可能很有趣并且可以提高代码的质量。

因此,我阅读了一些可用的资源,并选择了 SQL Developer 及其单元测试功能。

我遇到了一个愚蠢的问题,谷歌让我失败了。

我正在对一个简单的包进行单元测试。

--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;

通过实现:

--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;

输入字符串为035200220122102201213

结果是 - 错误。断言失败。 该过程是正确的,它返回正确的值,但“单元测试框架”通知我:

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>]

我在任何地方都找不到提交的错误 - metalink、Google - 有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筱武穆 2025-01-14 18:07:09

此页面 https://forums.oracle.com/forums/thread.jspa?threadID =2382730
说引用游标和单元测试存在问题......

也许与其相关。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文