如何为收集数据类型执行utplsql

时间:2019-05-16 07:38:04

标签: utplsql

我希望支持处理utplsql中ut_expect中的集合数据类型。

我想使用utplsql对以下软件包进行测试。我要检查日期数组。

create or replace PACKAGE pkg_BA_GetAccrualHist
AS
   TYPE arr_start_date IS TABLE OF VARCHAR2(12)
      INDEX BY BINARY_INTEGER ;

      CURSOR cur_BA_GetAccrualHist
      (
         p_ref_RefNum             IN  VARCHAR2(15)

      )
   IS
      SELECT TO_CHAR(A.start_date, 'MON DD,YYYY'),
              FROM ACCRUAL_HIST A
       WHERE A.ref_num           = p_ref_RefNum
               ORDER BY A.start_date;

    PROCEDURE sp_BA_GetAccrualHist_s
        (
            p_ref_RefNum         IN      accrual_hist.ref_num%TYPE,
            p_dat_StartDate         OUT  arr_start_date,
        );

END pkg_BA_GetAccrualHist;
create or replace PACKAGE BODY pkg_BA_GetAccrualHist
AS

   PROCEDURE sp_BA_GetAccrualHist_s
   (
        p_ref_RefNum         IN      accrual_hist.ref_num%TYPE,
        p_dat_StartDate         OUT  arr_start_date
    ) IS 

          i INTEGER ;

   BEGIN

      IF NOT cur_BA_GetAccrualHist%ISOPEN
      THEN
         OPEN cur_BA_GetAccrualHist (p_ref_RefNum);

     END IF;

      FOR i IN 1.. 10
      LOOP

         FETCH cur_BA_GetAccrualHist
         INTO  p_dat_StartDate(i);

         IF cur_BA_GetAccrualHist%NOTFOUND
         THEN
            CLOSE cur_BA_GetAccrualHist;
        end IF;
    END LOOP;
   END sp_BA_GetAccrualHist_s;
END pkg_BA_GetAccrualHist;

MY approach is 
create or replace package UT_pkg_BA_GetAccrualHist as
  --%suite(SUITE FOR pkg_BA_GetAccrualHist)

  --%test(TC1 When all the parameters are passed as '')
  procedure UT_sp_BA_GetAccrualHist_T1;

end;

create or replace PACKAGE BODY UT_pkg_BA_GetAccrualHist AS

    PROCEDURE UT_sp_BA_GetAccrualHist_T1 IS
    P_REF_REFNUM VARCHAR2(15);
    P_DAT_STARTDATE TRIMS.PKG_BA_GETACCRUALHIST.ARR_START_DATE;
    BEGIN
      P_REF_REFNUM := '123456789';

      PKG_BA_GETACCRUALHIST.SP_BA_GETACCRUALHIST_S(
    P_REF_REFNUM => P_REF_REFNUM,
    P_DAT_STARTDATE => P_DAT_STARTDATE);

此后,我不知道如何处理ut_expect中的收集数据类型。我已经尝试了很多事情,但是无法正常工作。

1 个答案:

答案 0 :(得分:0)

不幸的是,您的问题并没有说明您尝试过的方法以及它是如何工作的,但是总的来说,可以写出对集合的期望,但这确实需要一些额外的工作。

技巧是使用anydata.convertCollection(),如文档中所示(在这种情况下,对于一个对象表,但对于一个varchars表应该类似):

create type department as object(name varchar2(30))
/
create type departments as table of department
/

procedure test_departments is
  v_expected departments;
  v_actual   departments;
begin
  v_expected := departments(department('HR'), department('IT') );
  ut.expect( anydata.convertCollection( get_depts() ) ).to_equal( anydata.convertCollection( v_expected ) );
end;

有关对象,嵌套表和其他复杂类型的更详细的示例,请参见Object and nested table data-type comparison examples