If class has 74.5 % coverage then how can we increase 0.5% coverage without modifying test class?
-
You can’t. That’s not how test coverage works. Please see our standard resources on coverage, which I’ve linked above.– David Reed ♦Mar 28 at 13:20
-
You can increase it with some tweaks, but I would not recommend doing so, cause it is considered a really bad practice to do so. Simply saying, you can add more code to the covered blocks or reduce it in sections that are not covered.– azimut3Mar 28 at 13:45
1 Answer
As a short, pithy remark: you can't
If you need additional coverage, then the only correct way to go about doing that is by adding additional tests (making a new test class, adding tests to the existing test class).
Technically, refactoring the code being tested (the SUT, system under test) would be another potential approach as that could reduce the number of uncovered lines, but doing that while making sure you aren't breaking any tests is likely harder than just writing additional tests.
-
+1, but refactoring can be useful. Prune unreachable catch statements, fix impossible logic conditions for if/else/do/while/for, extract comparisons to Boolean values, remove obsolete methods, and so on. The exact techniques are circumstantial, though.– sfdcfoxMar 28 at 16:54