1

我是使用 utplsql 的新手,所以对我可能不理解的任何明显的事情表示歉意。我的问题是我刚刚创建了一个测试套件......

CREATE OR REPLACE PACKAGE BODY ut_test_pkg
IS 
   LP_business_date DATE;
   PROCEDURE ut_setup
   IS
   BEGIN
      select nvl(business_date,trunc(sysdate))
      into LP_business_date
      from my_ut_test_params;   
   END ut_setup;

   PROCEDURE ut_teardown
   IS
   BEGIN
      NULL; 
   END ut_teardown;

   PROCEDURE ut_ttable(I_business_part_date IN DATE)
   IS    
      L_dummy NUMBER:=0;      
   BEGIN
      select count(*) 
      into L_dummy
      from mytable
      where business_part_date=to_date('11/05/2013','dd/mm/yyyy')
      and length(trim(cust_order_no))>0;
      utassert.eq (
         'Successful CUST_ORDER_NO NOT EMPTY',
         L_dummy,
         0
      );  
      dbms_output.put_line('L_dummy ' || L_dummy);
   END ut_ttable;         
END ut_mytest_pkg;
/

现在我用 utplsql 定义测试...

BEGIN
   utsuite.add ('MY TEST SUITE');   
   -- Add two packages for testing
   utpackage.add ('MY TEST SUITE', 'ut_test_pkg');
END;
/

现在我运行测试套件...

set serveroutput on
begin
   utplsql.testSuite('MY TEST SUITE',recompile_in=>false);
end;
/

当我查询 UT_SUITE 表时,它告诉我执行计数增加并且最后一个状态是 SUCCESS 但是我不认为它正在运行我的测试过程 it_table 因为我故意添加了它失败的条件。

我还放入了一些打印语句,它没有打印到缓冲区。

有没有人知道我可能做错了什么?

哦,最后一件事.. .UTR 错误并没有告诉我它也失败了。

谢谢

4

2 回答 2

1

The problem is that, if you have for example a package Manage_cars, then all the testing code related to that package MUST be in a package ut_Manage_cars. utplsql needs all your testing packages to have the ut_ prefix (if you really really want, you can change this prefix somehow...anyway you still need a prefix for each package that contains testing procedures).

So in this case, when you want to add the package to the test suite you do something like :

utPackage.add('my_suite','Manage_cars');

Notice that when you add packages to the suite, you add the packages that contain the code that NEEDS TO BE TESTED. Not the code that contains the asserts and other utplsql related code(which MUST BE PLACED IN ut_Manage_cars)

Hope this helps..if not reply and i will answer as soon as posible :)

于 2013-05-28T08:28:33.820 回答
1

实际上,您可以在没有特定包的情况下运行测试(独立测试)。为此,请照常编写测试包,然后在测试套件定义中,在 utpackage.add() 中添加以下参数:

 samepackage_in => TRUE

此外,请确保在这种情况下您提供整个包名。所以在上面的例子中,它将是:

utPackage.add('my_suite','ut_Manage_cars', samepackage_in => TRUE);

这实际上用于当要测试的包还包含其测试代码时。但它也可以用来创建一个只包含测试代码的包,这些代码可以测试多个包,甚至是类似功能的集成。以这种方式使用,包名不必以 ut_ 前缀开头,但建议使用。

于 2016-07-06T06:56:04.660 回答