从一个模式到另一个模式执行UTPLSQL测试时遇到错误

时间:2015-02-18 04:37:21

标签: oracle unit-testing plsql

我已连接到' user1'并执行以下命令,utplsql安装在' utp'中。我从http://utplsql.sourceforge.net/安装了utplsql框架。

BEGIN
     utp.utAssert.eq('test',1,1); 
END; 
/

错误输出

ORA-02291: integrity constraint (UTP.UTR_ERROR_OUTCOME_FK) violated - parent key not found
ORA-06512: at "UTP.UTRERROR", line 149
ORA-06512: at "UTP.UTRERROR", line 324
ORA-06512: at "UTP.UTROUTCOME", line 146
ORA-01400: cannot insert NULL into ("UTP"."UTR_OUTCOME"."RUN_ID")
ORA-06512: at "UTP.UTRESULT2", line 72
ORA-06512: at "UTP.UTASSERT2", line 137
ORA-06512: at "UTP.UTASSERT2", line 541
ORA-06512: at "UTP.UTASSERT", line 118
ORA-06512: at line 2

但是

1 个答案:

答案 0 :(得分:3)

不是直接运行utAssert.eq,而是将其放入测试包中,然后使用utPLSQL.testutPLSQL.run运行 。 (我建议您完成Getting StartedutPLSQL documentation部分。

定义测试包

CREATE OR REPLACE PACKAGE ut_simple IS
    PROCEDURE ut_setup;
    PROCEDURE ut_teardown;
    PROCEDURE ut_simple_test;
END;

CREATE OR REPLACE PACKAGE BODY ut_simple IS
    PROCEDURE ut_setup IS
    BEGIN
        NULL;
    END;

    PROCEDURE ut_teardown IS
    BEGIN
        NULL;
    END;

    PROCEDURE ut_simple_test IS
    BEGIN
         utp.utAssert.eq('test',1,1); 
    END; 
END;

运行测试

exec utp.utplsql.run ('ut_simple');