0

How can I add an individual test result into a table. I want it in this format:

test_desc       | status
--------------------------------
this is test 1  | Pass
--------------------------------
this is test 2  | Fail
APC
  • 144,005
  • 19
  • 170
  • 281
Success Shrestha
  • 433
  • 1
  • 4
  • 19
  • Welcome to SO ;) Please read this article on [how to ask a good question](https://stackoverflow.com/help/how-to-ask). This would include a proper description of what you are trying to achieve, your code (or the relevant snippets) as well as your efforts showing what you have tried so far. In your case I would recommend to go through the docs and tutorials and try to grasp the general approach for what are you trying to achieve. – iLuvLogix Oct 11 '18 at 12:31

2 Answers2

2

Version 2.3.1 included a guide on how to create custom reporter packages. For version 3 I cannot find that in the documentation, but it still uses reporters for the different CI systems. As utPLSQL is licensed under the Apache 2.0 license, you can extend it for your needs and create your own reporter. Check out the existing reporters, in particular the ut_documentation_reporter as a starting point.

Daniel Frech
  • 335
  • 2
  • 10
0

You can call ut.run() as a table function, and return its results from a query. But those results will be a table of varchars. To extract useful information from that, you could parse those results a bit.

The query below works with the standard reporter, but is admittedly a bit rough around the edges and will give incorrect results if your test descriptions contain certain 'trigger' strings (like '[' or 'FAILED'). You could use another reporter, or write your own, to output the results in a format that is more easy to parse.

select
  substr(result, 1, instr(result, '[') - 1) as description,
  case 
    when result like '%(FAILED%' then
      'FAILED'
    when result like '%(DISABLED%' then
      'DISABLED'
    when result like '%(ERROR%' then
      'ERROR'
  else
    'OK'
  end as status
from
  ( -- Actual test run
    select 
      trim(column_value) as result 
    from 
      table(ut.run())
  )
where
  result like '%[%' /* filter out irrelevant lines */;

Once you've got your results like this, it's of course trivial to insert them into a table using an insert..select statement.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210