utPLSQL / utPLSQL-cli

Command line client for invoking utPLSQL
Apache License 2.0
40 stars 15 forks source link

Need help in command for generating the coverage report in UTPLSQL #187

Closed PriyankaKeer closed 3 years ago

PriyankaKeer commented 3 years ago

Hi,

Need help in generating coverage report in UTPLSQL CLI and SQL Developer Tests cases are written in a UnitTest schema and the "Procedures under Test" are residing in a user schema. 1. In UTPLSQL CLI, Tried the below command, but it was generating empty report:

utplsql run "connection string" -p=UT_SCHEMA -o=run.log -s -f=ut_coverage_html_reporter -o=coverage.html -include=USER_SCHEMA

2. In SQL Developer, Tried the below command, but the report is getting generated for the procedures residing in UT_SCHEMA though the Testcases are written for the Procedures residing in both USER_SCHEMA and UT_SCHEMA

SET SERVEROUTPUT ON FORMAT TRUNCATED begin ut.run(ut_coverage_html_reporter()); end; /

Please help us with commands( for UTPLSQL-CLI and SQL DEVELOPER) which generates coverage report for all the procedures in the user schema and UnitTest schema for which the testcases are written in UnitTest schema.

Thanks in Advance.

tplazaro commented 3 years ago

Same issue here :( Seems same bug with https://github.com/utPLSQL/utPLSQL-cli/issues/162I

I'm using utPLSQL 3.1.10 and utPLSQL-cli 3.1.8 (both latest version). I wonder if this is a regression issue and would work with lower version of utPLSQL

tplazaro commented 3 years ago

@PriyankaKeer I tried mirroring exact structure in https://github.com/utPLSQL/utPLSQL-demo-project it looks like it needs to have the same extensions and folder structure. It worked now for me.

jgebal commented 3 years ago

Hi @PriyankaKeer @tlazaro-lululemon

Did you read through the code coverage documentation? It outlines multiple variations of configuration for running utPLSQL with code coverage.

jgebal commented 3 years ago

@PriyankaKeer Also, the readme for utPLSQL-cli mentions parameter:

--coverage-schemes - A comma separated list of schemas on which coverage should be gathered
                     Format: --coverage-schemes=schema1[,schema2[,schema3]]

So I assume your command line should look like this:

utplsql run "connection string" -p=UT_SCHEMA -o=run.log -s \
 -f=ut_coverage_html_reporter -o=coverage.html --coverage-schemes=USER_SCHEMA

Also make sure that the user that is connecting to the database has correct privileges as mentioned in coverage documentation:

Security model utPLSQL code coverage uses DBMS_PROFILER to gather information about the execution of code under test and therefore follows the DBMS_PROFILER’s Security Model. In order to be able to gather coverage information, the user executing unit tests needs to be either:

The owner of the code that is being tested Have the following privileges to be able to gather coverage on code owned by other users: create any procedure system privilege execute privilege on the code that is being tested (not only the unit tests) or execute any procedure system privilege If you have execute privilege on the code that is being tested, but do not have create any procedure system privilege, then the code that is being tested will be reported as not covered (coverage = 0%). If you have execute privilege only on the unit tests, but do not have execute privilege on the code that is being tested, the code will not be reported by coverage - as if it did not exist in the database. If the code that is being tested is complied as NATIVE, the code coverage will not be reported as well.

jgebal commented 3 years ago

@PriyankaKeer In SQLDeveloper you can use command:

begin
  ut.run('unit_test_schema', ut_coverage_html_reporter(), a_coverage_schemes => ut_varchar2_list('user_1','user_2') );
end;

Also I recommend using SQL-Developer extension by Philip Salvisberg - it's briliant. See those blog posts: https://www.salvis.com/blog/2019/07/06/running-utplsql-tests-in-sql-developer/ https://www.salvis.com/blog/2020/06/07/utplsql-for-sql-developer-1-2-whats-new/