I've recently started using PostSharp in some of my projects and have noticed an unfortunate side effect - the code coverage in all the projects its used with drops significantly.
I'm guessing the reason this happens is that the analyzer sees the PostSharp code and a lot of it isn't tested (i.e. boiler plate code for generic exception handling and logging). I could obviously write unit tests for every method that use the aspects, but if I'm honest it feels like a waste of time.
Has anybody got any experience with this kind of thing?
Once we run the test method, While the unit test is passing, we need to check if our unit test covers the all code block for our method using the “Code Coverage”. Once the test execution successful, Visual Studio calculate the code coverage and display it within “Code Coverage Results” windows; as shown in below image.
To do this, edit your workspace settings to set salesforcedx-vscode-core. retrieve-test-code-coverage to true and then run your Apex tests. You can now see the code coverage in the Output panel, which shows the coverage percentage per Apex Class and Apex Trigger and lines that were not covered by the test run results.
In Visual Studio, click File > Open > File, navigate to the output directory of the solution, and select and open the run. coverage file.
To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.
What code coverage tool do you use? In PartCover, you can ignore some classes or namespaces, like MyProgram.PostSharp.*, to receive correct numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With