diff --git a/codeflash/languages/java/build_tools.py b/codeflash/languages/java/build_tools.py index ddb125a3d..3ba613729 100644 --- a/codeflash/languages/java/build_tools.py +++ b/codeflash/languages/java/build_tools.py @@ -706,6 +706,8 @@ def add_jacoco_plugin_to_pom(pom_path: Path) -> bool: return False # JaCoCo plugin XML to insert (indented for typical pom.xml format) + # Note: For multi-module projects where tests are in a separate module, + # we configure the report to look in multiple directories for classes jacoco_plugin = """ org.jacoco @@ -724,6 +726,12 @@ def add_jacoco_plugin_to_pom(pom_path: Path) -> bool: report + + + + **/*.class + + """.format(version=JACOCO_PLUGIN_VERSION) diff --git a/codeflash/result/critic.py b/codeflash/result/critic.py index 03a042131..f51762ddf 100644 --- a/codeflash/result/critic.py +++ b/codeflash/result/critic.py @@ -11,6 +11,7 @@ MIN_TESTCASE_PASSED_THRESHOLD, MIN_THROUGHPUT_IMPROVEMENT_THRESHOLD, ) +from codeflash.models.models import CoverageStatus from codeflash.models.test_type import TestType if TYPE_CHECKING: @@ -206,14 +207,17 @@ def quantity_of_tests_critic(candidate_result: OptimizedCandidateResult | Origin def coverage_critic(original_code_coverage: CoverageData | None) -> bool: """Check if the coverage meets the threshold. - For languages without coverage support (like JavaScript), returns True if no coverage data is available. - Java now uses JaCoCo for coverage collection and is subject to coverage threshold checks. + Returns True when: + - Coverage data exists, was parsed successfully, and meets the threshold, OR + - No coverage data is available (skip the check for languages/projects without coverage support), OR + - Coverage data exists but was NOT_FOUND (e.g., JaCoCo report not generated in multi-module projects) """ - from codeflash.languages import is_javascript - if original_code_coverage: + # If coverage data was not found (e.g., JaCoCo report doesn't exist in multi-module projects), + # skip the coverage check instead of failing with 0% coverage + if original_code_coverage.status == CoverageStatus.NOT_FOUND: + return True return original_code_coverage.coverage >= COVERAGE_THRESHOLD - # For JavaScript, coverage is not implemented yet, so skip the check - if is_javascript(): - return True - return False + # When no coverage data is available (e.g., JavaScript, Java multi-module projects), + # skip the coverage check and allow optimization to proceed + return True