[BUG]: Code coverage fails to capture execution flow interruptions #5506
Labels
bug
End user-perceivable behaviors which are not desirable.
Impact: Medium
Moderate perceived user impact (non-blocking bugs and general improvements).
Work: Low
Solution is clear and broken into good-first-issue-sized chunks.
Describe the bug
It is observed that lines of code involving termination statements - such as
exitProcess(1)
, assertion failures - such asassertThat(it).isNotPending()
and flow interruption statements - such asbreak
are not marked as covered even though they are executed.This appears to be a known issue with JaCoCo. According to JaCoCo documentation, source code lines that involve exceptions or abrupt termination sequences show no coverage because the control flow is interrupted. JaCoCo FAQ Page
As per documentation:
Steps To Reproduce
Consider the RetrieveChangedFiles.kt file with the following termination statement:
Generate code coverage report for the file RetrieveChangedFiles.kt:
bazel run //scripts:run_coverage -- $(pwd) scripts/src/java/org/oppia/android/scripts/ci/RetrieveChangedFiles.kt
Review the generated HTML code coverage report for RetrieveChangedFiles.kt:
With the DataProviderTestMonitor.kt, it is observed that the lines,
generate a coverage report of:
The coverage report indicates that the lines with
assertThat
andprintln("After Asserting...")
are not hit, which suggests they are not being executed during the test. Based on the test behavior, it seems that the assertion fails and throws an exception, interrupting the flow, causing the subsequent lines to be skipped.The finally block in SurveyProgressController.kt was reported as uncovered. The current code snippet is:
The report with break statement:
The report without break statement:
The partial coverage caused by the break statement suggests a potential alignment with the previously noted exception gap with JaCoCo.
Expected Behavior
The lines of code containing the termination statement (exitProcess(1)), assertThat(it).isNotPending(), break should be marked as covered if they are executed during a test run.
Additional Context
Other files that exhibit the behavior as (1 - Termination statements):
I suspect that the following code in
PinPasswordActivityPresenter
may also fall into the same category of termination statements.However, due to compatibility issues with code coverage tools (see tracking issue #5481), this file is currently exempted from coverage, making it difficult to determine the exact coverage details.
Bazel Version
6.5.0
What device/emulator are you using?
No response
Which Android version is your device/emulator running?
No response
Which version of the Oppia Android app are you using?
No response
The text was updated successfully, but these errors were encountered: