Closed fransf-wtax closed 4 months ago
OK, apparently the code coverage report you get from sf apex run test -c -r json
is vastly different from the one you get when running sf project deploy start --coverage-formatters=json
.
No ideas why two Salesforce CLI commands that essentially do the same thing would do that thing is such a different way...
@fransf-wtax - Thank you for reporting this issue.
Yes, this is due to the deltas between the JSONS created by the CLI's deploy command and the test command. I'm not sure why they follow different formats. But there are current bugs open against how deploy
returns covered lines in their coverage files and I don't think the issue happens with the test
command. You can refer to this issue on the CLI repo for more information on what's wrong with how deploy command return code coverage - https://github.com/forcedotcom/cli/issues/1568
In regards to supporting the sf apex run test
JSON coverage file, I have just released a new version of this plugin which should support the JSON interface of the test command.
Please this new version out when you can.
I tested this out with the coverage JSON example you provided (after updating file names to match my test files) and it was able to create coverage XMLs in the same format accepted by SonarQube.
sf plugins install apex-code-coverage-transformer@1.7.2
To run this plugin correctly for the test
command, you must supply this new command flag named --command
/-c
with the value "test"
. If you don't provide this new flag, it defaults to the "deploy" command which will use the different JSON interface.
sf apex-code-coverage transformer transform -j "coverage.json" -x "coverage.xml" -c "test"
@mcarvin8 This is amazing! I tried out the new plugin and the support for sf apex run test
reports and it works like a charm. Thank you!
Great news! Thanks for the update!
I was very excited to try this to get my Apex unit test coverage metrics into SonarQube!
However, when I run the transformer, I just get a list of similar warnings:
followed by an error:
Error (1): None of the files listed in the coverage JSON were processed.
No output file is created.
I'm not sure where it gets the "file name 0" etc. from. There are actual file names (more accurately, class names) in the test coverage report, e.g.
"name":"UTIL_ImportUtils"
The coverage file I'm trying to transform looks like this:
etc.
Any idea what the issue is here?
Thanks! Frans