utPLSQL-将参数(l_message)传递给过程。没有传递值。

时间:2018-10-12 11:45:19

标签: sql oracle unit-testing plsql utplsql

我有一个将值插入表中的过程。

showFile() {
    var fs = require('fs');
    var obj = fs.readFile('dic.txt', 'utf8');
    console.log(obj);
  }

  getItems(ev) {
    // Reset items back to all of the items
    this.initializeItems();

    // set val to the value of the ev target
    var val = ev.target.value;

    // if the value is an empty string don't filter the items
    if (val && val.trim() != '') {
      this.items = this.items.filter((item) => {
        this.showFile();
        return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
      })
    }
  }

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

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

参数未传递。我也无法在过程中打印该值。我想将测试状态/描述消息添加到现有表中。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

  1. 您缺少commit
  2. 请确保使它成为自主事务,否则您将提交所有内容,包括测试所做的更改。
  3. 创建一个自定义报告程序(例如my_reporter)以进行此插入。这样一来,您就可以分隔职责,避免在每次重新安装/升级utPLSQL时丢失更改。
  4. 使用utplsql-cli与多个报告者一起运行测试。
  5. 使用动态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;
/