utPLSQL - 将参数 (l_message) 传递到过程中。不传值。

utPLSQL - Passing argument(l_message) into a procedure. Not passing the value.

我有一个程序可以将值插入 table。

CREATE OR REPLACE PROCEDURE proc_test_status_table(
     p_test_description IN VARCHAR2,
     p_test_status IN varchar2)                                                
 AS    
  l_sql VARCHAR2(4000);
  BEGIN
  l_sql := 'insert into test_status_table(test_description, test_status)
            values
            ( '''||p_test_description||''',
              '''||p_test_status||''')';

  EXECUTE IMMEDIATE (l_sql);

END;
/

ut_documentation_reporter 我已将程序 after_calling_test 的代码修改为:

overriding member procedure after_calling_test(self in out nocopy ut_documentation_reporter, a_test ut_test) as
l_message varchar2(4000);
l_test_description VARCHAR(1000);
l_test_status VARCHAR(100);                                             
begin
l_message := coalesce(a_test.description, a_test.name)||' ['||round(a_test.execution_time,3)||' sec]';
--if test failed, then add it to the failures list, print failure with number
if a_test.result = ut_utils.gc_disabled then
  self.print_yellow_text(l_message || ' (DISABLED)');
  l_test_description := 'DISABLED';

  --calling procedure
  proc_test_status_table(l_message, l_test_description);

elsif a_test.result = ut_utils.gc_success then
  self.print_green_text(l_message);                            
  l_test_description := 'PASS';

  --calling procedure
  proc_test_status_table(l_message, l_test_description);

elsif a_test.result > ut_utils.gc_success then
  failed_test_running_count := failed_test_running_count + 1;
  self.print_red_text(l_message || ' (FAILED - ' || failed_test_running_count || ')');     
  l_test_description := 'FAIL';

  --calling procedure
  proc_test_status_table(l_message, l_test_description);

end if;

-- reproduce the output from before/after procedures and the test
self.print_clob(a_test.get_serveroutputs); end;

参数没有被传递。我也不能在过程中打印值。我想将消息测试 status/description 添加到现有的 table 中。

您可能在过程中错过了 COMMIT。插入语句需要提交将数据插入 table.

  1. 您缺少 commit
  2. 确保将其设为自主事务,否则您将提交所有内容,包括测试所做的更改。
  3. 创建一个自定义报告器(例如 my_reporter)来进行此插入。这样你就可以分开职责并避免在 re-install/upgrade utPLSQL.
  4. 时丢失你的更改
  5. 运行 您使用 utplsql-cli 对多名记者进行的测试。
  6. 当使用动态 sql 时,使用绑定变量 - 不要连接 - 你的 SQL 会更快也更安全(抵抗 SQL-注入)

示例:

create or replace procedure proc_test_status_table(
  p_test_description in varchar2,
  p_test_status in varchar2
) as    
  pragma auotonomous_transaction;
  l_sql varchar2(4000);
begin

  execute immediate 
    'insert into test_status_table(test_description, test_status)
     values( :desc, :stataus )'
     using p_test_description, p_test_status;
  commit;
end;
/

create or replace type my_reporter under ut_reporter_base(
  constructor function my_reporter(self in out nocopy my_reporter) return self as result,
  overriding member procedure before_calling_test(self in out nocopy my_reporter, a_test ut_test),
  overriding member procedure after_calling_test(self in out nocopy my_reporter, a_test ut_test),
  overriding member function get_description return varchar2

)
/

create or replace type body my_reporter as

  constructor function my_reporter(self in out nocopy my_reporter) return self as result,
  begin
    self.init($$plsql_unit);
    return;
  end;
  overriding member procedure before_calling_test(self in out nocopy my_reporter, a_test ut_test) is 
  begin 
    proc_test_status_table(
      coalesce(a_test.description, a_test.name),
      'Starting'
    );  
  end;
  overriding member procedure after_calling_test(self in out nocopy my_reporter, a_test ut_test) is 
  begin 
    proc_test_status_table(
      coalesce(a_test.description, a_test.name)||' ['||round(a_test.execution_time,3)||' sec]',
      ut_utils.test_result_to_char(a_test.result)
    );  
  end;
  overriding member function get_description return varchar2 is
  begin
    return 'My custom reporter to insert test status data into test_status_table';
  end;

end;
/