


You can get to this window by either clicking on the coverage indicator on the status bar, or by executing the SFDX: Show Code Coverage from the command palette: You can see three indicators, depending on the coverage percentage: Coverage The indicator in the status bar will only appear if the Apex class has tests coverage downloaded for such class. Once the test coverage has been downloaded by the Salesforce CLI, you can now see the code coverage for a specific Apex file in the status bar, and also the overall code coverage in a new window: Coverage in Status Bar To do this, go to Visual Studio Code menu File->Preferences->Settings and enter "coverage" in the search box, and then from the search results enable the Retrieve-test-code-coverage setting:Īfter that, just execute some tests as you normally would from the Test view: Make sure you have configured the preferences on the Salesforce extension to retrieve code coverage on test execution. The extension relies on the official Salesforce Extensions test runner which creates the necessary files used to show the code coverage. This extension shows a summary of the code coverage for all APEX classes in the current project. The configuration includes the Assembly Attribute, from above, and all my common PackageReferences I like to use in my tests.Salesforce APEX Code Coverage Visualizer for Visual Studio Code Introduction Include the code below in a file at the root of your tests folder, where all your projects are located. Īnd here is a Bonus Snippet! I use this to simplify and consolidate all the base settings for my Test Projects. Code SnippetĪnd here it is, in your csproj just add this Assembly Attribute, and now your project will not have its code coverage metric tallied. Well I do not want this done on my test projects, since I don't test my tests. I have a large solution and an extension that will give me feedback on my code coverage, well by default it will also give you the metrics. NET test projects to be excluded them from code coverage metrics collection. This article as a code snippet I use with my.
