Toad World® Forums

Run tests from a command-line invocation of Code Tester


#1

Our organization uses NAnt (nant.sourceforge.net) for build/unit test of .net, VB, Powerbuilder, etc code, most of which has database dependencies. We’d like to be able to create tests for the different sets of dependencies and use NAnt to run a batch file which invokes Code Tester with the name of the test as a parameter, then queries the repository for test results and creates a semaphore file for NAnt to use as an indicator of success/failure.
Is it possible to invoke Code Tester from a command line, passing a test (test set) name, and have those tests run without involing the GUI?


#2

Absolutely! Code Tester relies on a PL/SQL API to generate and run tests. Check out the help documentation topic: “PL/SQL API to Quest Code Tester Features”.

Let me know if you need more details than this.

SF


#3

The documentation within Code Tester was helpful. However, being new to ref cursors, I am understanding how to get info out of the db using the ref cursor. From what I understand, I should be able to use the returned ref_cursor from the procedure qu_test.run_test_for() to retrieve information from the qu_outcome table or qu_result table, using the parent key: result_universal_id. I was wondering if you could supply an example.

Thanks.


#4

Carol, you are absolutely right! The documentation is not sufficient. I realized that when I went about building the example script (below). In the next release of the tool, I will put some of the smarts you see below into the api code itself, so you won’t have to write all this (there sure wasn’t any way for you to figure it out! :frowning: ):

DECLARE
l_result qu_config.maxvarchar2;
l_result_row qu_result_xp.last_run_results_cur%ROWTYPE;
my_results sys_refcursor;

FUNCTION name_for_level_guid (
result_level_in IN VARCHAR2
, guid_in IN VARCHAR2
)
RETURN VARCHAR2
IS
l_name qu_config.maxvarchar2;
l_harness qu_harness_tp.qu_harness_rt;
l_ut qu_unit_test_tp.qu_unit_test_rt;
l_tc qu_test_case_tp.qu_test_case_rt;
l_oc qu_outcome_tp.qu_outcome_rt;
BEGIN
CASE result_level_in
WHEN qu_result_xp.c_suite
THEN
l_name := qu_suite_qp.name_for_universal_id (guid_in);
WHEN qu_result_xp.c_harness
THEN
l_harness := qu_harness_qp.onerow (guid_in);
l_name :=
l_harness.program_owner || ‘.’ || l_harness.program_name;
WHEN qu_result_xp.c_unit_test
THEN
l_ut := qu_unit_test_qp.onerow (guid_in);
l_name := l_ut.NAME;
WHEN qu_result_xp.c_test_case
THEN
l_tc := qu_test_case_qp.onerow (guid_in);
l_name := l_tc.NAME;
WHEN qu_result_xp.c_outcome
THEN
l_oc := qu_outcome_qp.onerow (guid_in);
l_name := l_oc.NAME;
END CASE;

  RETURN l_name;

END name_for_level_guid;
BEGIN
qu_test.run_test_for (owner_in => USER
, NAME_IN => ‘program-name’
, failures_only_in => FALSE
, result_out => l_result
, results_out => my_results
);
DBMS_OUTPUT.put_line ('Overall result of test: ’ || l_result);

LOOP
FETCH my_results
INTO l_result_row;

  EXIT WHEN my_results%NOTFOUND;
  DBMS_OUTPUT.put_line
                 (   RPAD (' ',l_result_row.h_level)
                  || ' '
                  || name_for_level_guid (l_result_row.result_level
                                        , l_result_row.result_universal_id
                                         )
                  || '-Status: '
                  || l_result_row.result_status
                  || '-Description: '
                  || l_result_row.Description
                 );

END LOOP;
END;


#5

Aha. Thanks. I added start time and end time as well. Very nice way to format and add info to the log file or a temp file for diff purposes.

One issue, I don’t get output for l_result. Success or Failure, there is no output. I found this to be true when running this way as well.

– in variables
VARIABLE owner_in VARCHAR2(100);
VARIABLE name_in VARCHAR2(100);
VARIABLE result_out VARCHAR2(100);
VARIABLE my_results_out REFCURSOR;

exec qu_test.run_test_for(owner_in => USER,name_in => ‘name_here’,failures_only_in => FALSE, result_out => :result_out, results_out => :my_results_out);

print result_out my_results_out;

Note: I get info for the ref_cursor but not result_out.


#6

Carol, thanks for your very helpfull input.
Steve, thanks for the great ideas. I’m just wild-guessing here, but it looks like you are scratching a commonly-felt itch with this product.

One more little tidbit just in case I sucumb to senility (or another dot-net coder) before the end of the day: NAnt can treat the existence of a semaphore file as a true-positive or true-negative. The PL/SQL code I write can use some means (utl_file, java, spool and select from dual) to create a 0-byte file to indicate that the tests passed or delete such a file to indicate failure. NAnt scripts can treat the existence of this semaphore file as if it were a zero return code from a compile/build tool, or the absence of the file as a non-zero return code. This makes rollup of results to NAnt very simple, and NAnt can halt the build/test of non-oracle components if the file does not exist.


#7

Sigh…yes, that is a bug and we will have it fixed in the next release.

Thanks, SF


#8

Hi

Has there been any updates to the command line invocation of code tester since 2006?

Thanks


#9

Lots and lots. Check the help doc of the current release. If you feel that something is missing, let us know!

SF