0
0
JUnittesting~5 mins

Line and branch coverage in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is line coverage in software testing?
Line coverage measures the percentage of code lines executed by tests. It shows which lines ran during testing.
Click to reveal answer
beginner
Define branch coverage.
Branch coverage checks if each possible path (true/false) in decision points like if-else statements is tested.
Click to reveal answer
intermediate
Why is branch coverage important beyond line coverage?
Branch coverage ensures all decision outcomes are tested, catching bugs missed by line coverage alone.
Click to reveal answer
intermediate
Example: What does 100% line coverage but 50% branch coverage mean?
All lines ran, but only half of decision paths (branches) were tested. Some conditions may be untested.
Click to reveal answer
beginner
How can JUnit tests help improve branch coverage?
By writing tests that cover all if-else outcomes and loops, JUnit tests increase branch coverage.
Click to reveal answer
What does line coverage measure?
AExecution time of tests
BNumber of test cases written
CNumber of bugs found
DPercentage of executed code lines
Branch coverage ensures testing of:
AAll decision outcomes (true/false)
BAll variables
CAll lines of code
DAll classes
If a test covers every line but misses some branches, coverage is:
A100% line, 100% branch
B100% line, less than 100% branch
CLess than 100% line, 100% branch
DLess than 100% line and branch
Which JUnit feature helps check coverage?
AAssertions
BAnnotations only
CTest runners with coverage tools
DException handling
Branch coverage is especially useful for testing:
ALoops and conditions
BComments
CVariable declarations
DClass names
Explain the difference between line coverage and branch coverage.
Think about code lines vs decision points.
You got /3 concepts.
    How can you write JUnit tests to improve branch coverage?
    Consider all possible paths in your code.
    You got /3 concepts.