117
votes
Accepted
Code coverage highlights unused methods - what should I do?
Delete.
Commit.
Forget.
Rationale:
Dead code is dead. By its very description it has no purpose. It may have had a purpose at one point, but that is gone, and so the code should be gone.
Version ...
55
votes
Code coverage highlights unused methods - what should I do?
All other answers are based on the assumption that the methods in question are really unused. However, the question didn't specify whether this project is self-contained or a library of some sort.
If ...
47
votes
Unexpected Code Coverage Reduction
The problem I see here is that you have made the code coverage a trigger for build failure. I do believe that code coverage should be something that is routinely reviewed, but as you have experienced,...
37
votes
Unexpected Code Coverage Reduction
Have you considered not using code coverage metrics?
I'm not going to argue that code coverage isn't something that you should look at. It absolutely is. It's good to keep track of what was covered ...
30
votes
Code coverage highlights unused methods - what should I do?
First check that your code coverage tool is correct.
I've had situations where they haven't picked up on methods being called via references to the interface, or if the class is loaded dynamically ...
18
votes
Accepted
Unexpected Code Coverage Reduction
You can mitigate the effect to some degree by allowing the relative code coverage to reduce when the total number of uncovered lines also reduces, or when the total number of lines reduces, since this ...
15
votes
Unexpected Code Coverage Reduction
This is called Simpson’s paradox, and is a well known statistical issue with your approach.
You could even construct cases where you refactor and afterwards every single method has a higher coverage, ...
15
votes
Code coverage highlights unused methods - what should I do?
As Java is statically compiled, it should be pretty safe to remove the methods. Removing dead code is always good. There is some probability that there is some crazy reflection system which runs them ...
14
votes
Accepted
Are unit tests written purely to satisfy a code coverage figure technical debt?
Yes, I'd say these are technical debt. Test code is not different than the code being tested in that it must also be maintained and understood. The fact that you don't understand the point of the ...
11
votes
Accepted
If 100% test coverage is possible
There are strategies that can produce deep code coverage metrics. Mutation testing is one example. Roughly speaking, mutation testing ensures that any logical change to the program results in a failed ...
9
votes
Code coverage highlights unused methods - what should I do?
What would the best approach be? Write unit tests for them, or question why they're there?
Deleting code is a good thing.
When you can't delete the code, you can certainly mark it as @Deprecated, ...
9
votes
If 100% test coverage is possible
100% test coverage is possible, and despite 100% coverage, your program may still have errors. See shortcomings of test coverage at "Does path coverage guarantee finding all bugs?"
Similar to how a ...
9
votes
Code coverage highlights unused methods - what should I do?
A code coverage tool is not all-knowing, all-seeing. Just because your tool claims that the method is not called, that doesn't mean it isn't called. There is reflection, and depending on the language ...
8
votes
Accepted
How to comprehensively test software that doesn't play well with testing?
I'm afraid there is no easy solution. "write testable code" really is the only way to do it.
Writing testable code is non-trivial, and retro-fitting tests is hard. Many of the advances in modern ...
7
votes
Rerun unit tests affected by change
No, it wouldn't be a good idea.
The point of a test suite is to ensure that development doesn't introduce defects anywhere without having to reason about which parts of the program affect which. If ...
7
votes
How to comprehensively test software that doesn't play well with testing?
You are not alone
Though a redundant mention, anyone reading this question while not having this kind of trouble ought to remember that real-life software development is full of cases of multi-year ...
6
votes
Accepted
How is code coverage measured?
Code coverage tools work in two flavours:
either the code is instrumented to record coverage statistics, or
the program is run under a debugger or profiler, or tracing mechanism.
Coverage measurement ...
6
votes
Code coverage highlights unused methods - what should I do?
Depending on the environment the software runs in, you could log if the method is ever called. If it's not called within a suitable period of time, then the method can be safely removed.
This is a ...
5
votes
Rerun unit tests affected by change
Yes, this is a know technique that is valuable for getting more relevant test results more quickly. The mild drawback that only selecting possibly-affected tests makes the test result more fragile can ...
5
votes
Unexpected Code Coverage Reduction
While all answers are telling not to use code coverage as a quality metrics, none really answered the question. What to do with reduced coverage?
The answer is quite simple: use absolute numbers, not ...
4
votes
Rerun unit tests affected by change
Yes. For JavaScript there is https://wallabyjs.com/
From their homepage:
The tool is insanely fast, because it only executes tests affected by your code changes and runs your tests in parallel.
4
votes
Why is a test coverage type called "code coverage"?
Test coverage is a pretty straightforward term which doesn't need any explanation: how much is something "covered" by tests.
If you consider that there can be multiple "something"...
3
votes
If 100% test coverage is possible
You can have 100% coverage, but the question is: does it mean anything?
Personally, I would rather have 60% coverage of the important methods and their scenarios, than 100% coverage of non-relevant ...
3
votes
Accepted
Is it possible to derive a test suite to achieve 100% path coverage?
In theory? No. As that would be equivalent to solving the halting problem. You would need to enumerate infinite number of inputs to cover all the possible paths. Which is clearly impossible.
In ...
3
votes
Hypothetically if every scenario were covered by an end-to-end tests, would unit tests still have any value?
It's the second one.
Tests can demonstrate the capabilities of the system X as of now. But virtually always, requirements change and we will have to create a new System X' with subtle or big changes. ...
3
votes
Hypothetically if every scenario were covered by an end-to-end tests, would unit tests still have any value?
End-to-end tests and unit tests complete each other. They test code from different perspectives. End-to-end tests are focusing on a given feature, as it is implemented. Unit tests, on the other hand, ...
3
votes
Accepted
Test coverage for various code logic permutations... Metadata/Artifacts in algorithm results to describe which case?
This is called Branch coverage, and you find it in the Wikipedia article about Code coverage.
There are surely tools for some of the major development ecosystems which can measure the amount of code ...
3
votes
Accepted
Test driven reduction of technical debt
Technical debt takes on many forms not detectable by unit tests.
For example:
API function names written in Swahili. Team only speaks Esperanto.
Codebase uses KORBA. No one supports KORBA.
Contractor ...
3
votes
Covering a NO-OP Condition
Automated checking tools have the purpose of catching errors made through thoughtlessness. That is why they almost always have overrides to declare "Yes, I did think about that condition and it'...
3
votes
Accepted
Covering a NO-OP Condition
The core issue here is that the static analysis tool doesn't know if the method Encode.forJava(bar) has a beneficial side effect. I.e. that if you didn't call it that something else would break.
I am ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
test-coverage × 78testing × 37
unit-testing × 36
tdd × 8
integration-tests × 6
java × 5
code-quality × 5
test-automation × 3
junit × 3
python × 2
refactoring × 2
code-reviews × 2
mocking × 2
conditions × 2
quality × 2
functional-testing × 2
cyclomatic-complexity × 2
end-to-end × 2
object-oriented × 1
algorithms × 1
javascript × 1
programming-practices × 1
.net × 1
performance × 1
coding-standards × 1