diff --git a/cover_agent/CoverageProcessor.py b/cover_agent/CoverageProcessor.py index 13063fd2b..b459820c9 100644 --- a/cover_agent/CoverageProcessor.py +++ b/cover_agent/CoverageProcessor.py @@ -227,9 +227,10 @@ def parse_coverage_report_jacoco(self) -> Tuple[list, list, float]: missed, covered = 0, 0 if file_extension == 'xml': - missed, covered = self.parse_missed_covered_lines_jacoco_xml( + lines_missed, lines_covered = self.parse_missed_covered_lines_jacoco_xml( class_name ) + missed, covered = len(lines_missed), len(lines_covered) elif file_extension == 'csv': missed, covered = self.parse_missed_covered_lines_jacoco_csv( package_name, class_name @@ -244,7 +245,7 @@ def parse_coverage_report_jacoco(self) -> Tuple[list, list, float]: def parse_missed_covered_lines_jacoco_xml( self, class_name: str - ) -> tuple[int, int]: + ) -> tuple[list, list]: """Parses a JaCoCo XML code coverage report to extract covered and missed line numbers for a specific file.""" tree = ET.parse(self.file_path) root = tree.getroot() @@ -254,14 +255,14 @@ def parse_missed_covered_lines_jacoco_xml( ) if sourcefile is None: - return 0, 0 - - missed, covered = 0, 0 - for counter in sourcefile.findall('counter'): - if counter.attrib.get('type') == 'LINE': - missed += int(counter.attrib.get('missed', 0)) - covered += int(counter.attrib.get('covered', 0)) - break + return [], [] + + missed, covered = [], [] + for line in sourcefile.findall('line'): + if line.attrib.get('mi') == '0': + covered += [int(line.attrib.get('nr', 0))] + else : + missed += [int(line.attrib.get('nr', 0))] return missed, covered diff --git a/cover_agent/version.txt b/cover_agent/version.txt index 08456a479..d81f1c3fc 100644 --- a/cover_agent/version.txt +++ b/cover_agent/version.txt @@ -1 +1 @@ -0.2.8 \ No newline at end of file +0.2.9 \ No newline at end of file diff --git a/tests/test_CoverageProcessor.py b/tests/test_CoverageProcessor.py index 39330afa8..4c06f1f14 100644 --- a/tests/test_CoverageProcessor.py +++ b/tests/test_CoverageProcessor.py @@ -87,7 +87,7 @@ def test_returns_empty_lists_and_float(self, mocker): ) mocker.patch( "cover_agent.CoverageProcessor.CoverageProcessor.parse_missed_covered_lines_jacoco_xml", - return_value=(0, 0), + return_value=([], []), ) # Initialize the CoverageProcessor object @@ -301,6 +301,13 @@ def test_parse_missed_covered_lines_jacoco_xml_no_source_file(self, mocker): xml_str = """ + + + + + + + @@ -326,8 +333,8 @@ def test_parse_missed_covered_lines_jacoco_xml_no_source_file(self, mocker): ) # Assert - assert missed == 0 - assert covered == 0 + assert missed == [] + assert covered == [] def test_parse_missed_covered_lines_jacoco_xml(self, mocker): #, mock_xml_tree @@ -339,6 +346,13 @@ def test_parse_missed_covered_lines_jacoco_xml(self, mocker): xml_str = """ + + + + + + + @@ -364,8 +378,8 @@ def test_parse_missed_covered_lines_jacoco_xml(self, mocker): ) # Assert - assert missed == 9 - assert covered == 94 + assert missed == [39, 40, 41] + assert covered == [35, 36, 37, 38] def test_parse_missed_covered_lines_kotlin_jacoco_xml(self, mocker): #, mock_xml_tree @@ -377,6 +391,13 @@ def test_parse_missed_covered_lines_kotlin_jacoco_xml(self, mocker): xml_str = """ + + + + + + + @@ -402,8 +423,8 @@ def test_parse_missed_covered_lines_kotlin_jacoco_xml(self, mocker): ) # Assert - assert missed == 9 - assert covered == 94 + assert missed == [39, 40, 41] + assert covered == [35, 36, 37, 38] def test_get_file_extension_with_valid_file_extension(self): processor = CoverageProcessor( diff --git a/tests/test_UnitTestValidator.py b/tests/test_UnitTestValidator.py index 147ca91dc..06c5dc7b1 100644 --- a/tests/test_UnitTestValidator.py +++ b/tests/test_UnitTestValidator.py @@ -104,7 +104,7 @@ def test_validate_test_pass_no_coverage_increase_with_prompt(self): result = generator.validate_test(test_to_validate) assert result["status"] == "FAIL" - assert result["reason"] == "Coverage did not increase" + assert result["reason"] == "Coverage did not increase. Maybe the test did run but did not increase coverage, or maybe the test execution was skipped due to some problem" assert result["exit_code"] == 0 def test_initial_test_suite_analysis_with_prompt_builder(self):