Apex Testing: test-result.md report, "Poorly Covered Tests" section - purpose unclear; allow removing the section via config #7103
AndrewStopchenko-SO
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem 1 - "Poorly Covered Tests" section ("Test Quality Warnings" sub-header), struggling to understand the coverage intent (action to improve?)
When working in a project with many Apex classes and Apex Test classes, the "Poorly Covered Tests" section does not make much sense, because it displays a per-test-method coverage % across total apex class lines count, and the section is quite noisy - e.g. in one of the projects I received 573 poorly covered tests, but I have no idea how this information helps me or what it suggests me to do about it.
How this works now
Out of curiosity, I created a small Apex class with 3 dummy methods, and a Test class to invoke each of those methods.
Sample Apex class:
Sample Apex Test class:
Then, I ran all tests in the
Coverage1_Test. The resultingtest-result-{testRunId}.mdfile preview shows the following:So, the "Poorly Covered Tests" section shows each test method of the test class, and the coverage % next is what appears to be the formula:
Okay, but - what does this
coverage %value tell me about my unit tests, or how to improve them? If the low coverage % of a single test method implies that the test method is "bad" (though, I tend to disagree with this), how should one fix that?Could be opinionated, but I usually write Apex test methods so that a testMethod focuses on validating the logic and edge cases of a single being-tested class method. Sometimes, even multiple testMethods may aim at covering some edge cases or "highload" scenarios for a single being-tested class method. But with the
coveragePercentstatistic above, it suggests that the testMethod should aim at covering as many tested class's lines as possible - the better the coverage % will be then, right?In its current form, this section's information looks excessive and redundant; it grows exponentially as we include more Apex classes, or if we include more ApexTests in the test run.
Suggestions
ClassName(as opposed to "Code Coverage by Class" sorted bycoverage %), making it faster & easier to scan diagonally.Problem 2 - "Test Results with Coverage" section, ClassBeingTested shows
TestClassName, not the being-testedApexClassName(as expected).Please pay attention to the "Test Results with Coverage" section output.
I was hoping that this section provides a breakdown of the coverage % for some specific being-tested
ApexClassNameas it is achieved by some particulartestClass-testMethodtest method's execution (e.g. if someClassAmethod1, method2, method3 were invoked byClassATest.testMethod1()andClassATest.testMethod2()methods, we'd know how those individualClassATestmethods contributed to thatClassAcoverage).So, my understanding was that this section tries to reflect the functionality of DevConsole, where we:
testClass-testMethodruns.At least that was my (apparently wrong) understanding, when looking at the report for test run in a real-world project (500+ tests), where the resulting data table is really long and "data-intensive".
But in this single-test-class example above, the "Class Being Tested" table's column shows ... the
TestClassNamevalues.But, why?.. Honestly, I struggle to understand what exactly the number means here - like, out of
totalCoveredLinesByTestClass, what percentage of them were covered thanks to some particulartestMethodof thattestClass?..In other words, this seems like the same problem as Problem 1 - the table displays the same kind of coverage information as the "Poorly Covered Tests", just in a fancier way ("Pass"/"Fail" info; runtime milliseconds).
Summary
When we run unit tests, the final objective is to know the coverage of how many lines of the actual logic (ApexControllers/services/utility classes) was achieved with this test run, or what tests have failed.
Right now, we receive the coverage of the
testMethodcovered lines, across theTestClasstotal covered lines.Salesforce Extension Version in VS Code: 66.3.2
Salesforce CLI Version: @salesforce/cli/2.128.5 win32-x64 node-v22.22.1
OS and version: Windows_NT x64 10.0.19045
VS Code version: 1.113.0
Beta Was this translation helpful? Give feedback.
All reactions