Mapping Source and Test folders for SonarCloud #184
Comments
|
Hi @rafael-trevisan
The key things to know are:
|
|
Hi @jgebal, For a file like The schema name where it's been deployed is a "run time" schema like BUILD_1, BUILD_2, BUILD_3 and etc. Each time a commit happens, the CI is creating a brand new schema, then Flyway re-creates the database including the UT and utPLSQL takes action running the test in that brand new schema. I am connecting utPLSQL with the same "run time" user ( Test owner is the same as src owner, however, I do have other schemas in the database with the same packages (both for logic and test). |
|
If it helps, this is the
|
|
So I took the default mapping regex parameters we have: gc_file_mapping_regex constant varchar2(100) := '/(((\w|[$#])+)\.)?((\w|[$#])+)\.(\w{3})$';
gc_regex_owner_subexpression constant positive := 2;
gc_regex_name_subexpression constant positive := 4;
gc_regex_type_subexpression constant positive := 6;
Modified it and tested on regex101 - you can see example here: Then I ran the below test-cases in SQL console to verify mappings: create or replace package package_a as
function f return integer;
end;
/
create or replace package body package_a as
function f(a integer) return integer is
x integer := 0;
begin
if a = 2 then
x := 1;
else
x := x + 3;
end if;
return x;
end;
end;
/
create or replace package test_package_a as
--%suite
--%test
procedure proc;
end;
/
create or replace package body test_package_a as
procedure proc is
begin
ut.expect(package_a.f(0) ).to_equal( 1 );
end;
end;
/Running with sonar coverage reporter - mapping source packages: begin
ut.run(
'test_package_a',
ut_coverage_sonar_reporter(),
a_source_file_mappings => ut_file_mapper.build_file_mappings(
a_file_paths => ut_varchar2_list(
'src/packages/r__package_a_spec.pks',
'src/packages/r__package_a_spec.pkb',
'src/packages/r__package_b_spec.pks',
'src/packages/r__package_b_spec.pkb'
),
a_regex_pattern => '/r__((\w|[$#])+)_(spec|body)\.(\w{3})$',
a_object_owner_subexpression => 9,
a_object_name_subexpression => 1,
a_object_type_subexpression => 4
)
);
end;
/Outcomes:
Running with sonar test reporter - mapping test packages: begin
ut.run(
'test_package_a',
ut_sonar_test_reporter(),
a_test_file_mappings => ut_file_mapper.build_file_mappings(
a_file_paths => ut_varchar2_list(
'test/packages/r__test_package_a_spec.pks',
'test/packages/r__test_package_a_body.pkb',
'test/packages/r__test_package_b_spec.pks',
'test/packages/r__test_package_b_body.pkb'
),
a_regex_pattern => '/r__((\w|[$#])+)_(spec|body)\.(\w{3})$',
a_object_owner_subexpression => 9,
a_object_name_subexpression => 1,
a_object_type_subexpression => 4
)
);
end;Outcomes:
So conclusion is as follows:
|
|
That’s amazing! I’ll test it here in a hour or so and will share the results. |
|
This is assuming that: You can play around with the regex if needed. One thing to note is that I've specified a non existing matching group value |
|
Makes total sense. Thanks for detailing. Wondering here if I should use the -p parameter to indicate which schema to run the tests as I have multiple schemas with the same packages. |
|
No need, as you connect as schema owner so this is default. |
|
Worked like a charm. Great thanks.
However I don't see (or don't know yet where to see) this information on the SonarCloud as it still shows 0% of coverage and the line I am sure it's being tested shows in red "Not covered by tests". I will reach out to SonarCloud folks to see what missing, anyways great thanks again. |
Hi,
I've been struggling to properly map the
sourceandtestfolders to avoid SonarCloud complaining:This is what I am using:
The project folder looks like:
I think the problem is the "spec" and "body" that I have to append to the filenames due to Flyway, but I am don't know how to get the
-regex_expressionthing right.Another strange thing is that the coverage report is blank. This is the sample content:
Any thoughts will be very appreciated.
The text was updated successfully, but these errors were encountered: