Questions tagged [test-coverage]
76 questions
139
votes
7 answers
What should you test with unit tests?
I'm freshly out of college, and starting university somewhere next week. We've seen unit tests, but we kinda not used them much; and everyone talks about them, so I figured maybe I should do some.
The problem is, I don't know what to test. Should I…

zneak
- 2,556
- 2
- 23
- 24
65
votes
11 answers
Does path coverage guarantee finding all bugs?
If every path through a program is tested, does that guarantee finding all bugs?
If not, why not? How could you go through every possible combination of program flow and not find the problem if one exists?
I hesitate to suggest that "all bugs" can…
user155884
60
votes
7 answers
Code coverage highlights unused methods - what should I do?
I have been tasked to increase code coverage of an existing Java project.
I noticed that the code coverage tool (EclEmma) has highlighted some methods that are never called from anywhere.
My initial reaction is not to write unit tests for these…

Lucas T
- 753
- 1
- 5
- 9
38
votes
11 answers
Unexpected Code Coverage Reduction
I am adding unit tests to some existing code which initially was not tested at all.
I have set up my CI system to fail builds where the code coverage percentage is reduced compared to previous build - mainly to set a path of continuing…

Jonathan Gross
- 545
- 1
- 4
- 9
25
votes
5 answers
How to drastically improve code coverage?
I'm tasked with getting a legacy application under unit test. First some background about the application: It's a 600k LOC Java RCP code base with these major problems
massive code duplication
no encapsulation, most private data is accessible from…

Peter Kofler
- 865
- 2
- 8
- 15
21
votes
7 answers
Is test coverage an adequate measure of code quality?
If I have some code that has 80% test coverage (all tests pass), is it fair to say that it's of higher quality than code with no test coverage?
Or is it fair to say it's more maintainable?

David_001
- 2,762
- 2
- 26
- 27
20
votes
9 answers
How do you unit-test code using graph structures?
I am writing (recursive) code that is navigating a dependency graph looks for cycles or contradictions in the dependencies. However, I am not sure how to approach unit testing this. The problem is that one of our main concerns is will the code…

Sled
- 1,868
- 2
- 17
- 24
19
votes
1 answer
Does it make sense to measure conditional coverage for Java 8 code?
I'm wondering whether measuring conditional code coverage by current tools for Java are not obsolete since Java 8 came up. With Java 8's Optional and Stream we can often avoid code branches/loops, which makes it easy to get very high conditional…

Karol Lewandowski
- 349
- 2
- 8
15
votes
2 answers
How do I know if I have enough unit test coverage to remove an integration test?
I'm working on a legacy system (by that I mean it was written without tests). We've tried to test some of the system by writing integration tests that test functionality from the outside.
This gives me some confidence to refactor parts of the…

Daniel Kaplan
- 6,776
- 5
- 32
- 46
15
votes
4 answers
Unit testing internal components
To what extent do you unit test internal/private components of a class/module/package/etc? Do you test them at all or do you just test the interface to the outside world? An example of these internal is private methods.
As an example, imagine a…

imgx64
- 2,168
- 14
- 20
15
votes
5 answers
How can I design test cases to cover code based on random events?
For example, if the code generates a random int from 0-10, and takes a different branch on each outcome, how can one design a test suite to guarantee 100% statement coverage in such code?
In Java, the code might be something like:
int i = new…

Midhat
- 302
- 2
- 6
14
votes
6 answers
Does Code Coverage improve code quality?
I am curious whether there are metrics on whether code coverage actually improves code quality? Any research studies?
If so, at what percent does it become a case of diminishing returns?
If not, why do so many people treat it as a religious…

AngryHacker
- 715
- 1
- 6
- 11
13
votes
3 answers
How would you test Google Maps "Get Directions" feature?
(I imagine this would be a good interview question, but in my case it's more pragmatic than that.)
We have a large & complex application that models an extremely long and sophisticated chemical reaction process between dozens of chemical…

kmote
- 3,322
- 6
- 24
- 33
11
votes
1 answer
When does it make sense to include test code in coverage?
Many coverage tools evaluate an entire project, including unit test code itself. In VS 2013, the Analyze Code Coverage/All Tests option includes test code in its report. OpenCover does so as well I believe. In Eclipse, a Maven project with the…

Dan1701
- 3,118
- 1
- 15
- 24
11
votes
2 answers
Separate code coverage reports for unit and integration tests, or one report for both?
Should there be a separate code coverage report for unit and integration tests, or one code coverage report for both?
The thinking behind this is that code coverage allows us to make sure that our code has been covered by tests as far as possible…

Marios
- 303
- 3
- 8