Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JaCoCo for Code Coverage Reports in Pass Core #107

Merged
merged 9 commits into from
Jan 7, 2025
Merged

Conversation

tsande16
Copy link
Contributor

@tsande16 tsande16 commented Dec 21, 2024

This PR will add JaCoCo (Java Code Coverage) to the pass-core project. It is mostly the default configuration for JaCoCo. The reports are aggregated into the jacoco-aggregate-report module. In my research this is the approach to take when setting up an aggregate report to be consumed by a report service like SonarQube.

  • Report can be found in target/site/jacoco/index.html in the jacoco-aggregate-report module
    • Reports on individual classes are found in subfolders such as target/site/jacoco/org.eclipse.pass.support.client etc. These can be navigated to by using the index.html
  • I removed the coverage ratio so it wouldn't fail the build as we determined in our last status meeting, the first iteration will be just to view the reports and then determine what type of metrics to fail a build.
  • There was some minor javadoc added to the FileService.

To generate the reports:

  • run mvn verify

@tsande16 tsande16 self-assigned this Dec 21, 2024
@tsande16 tsande16 linked an issue Dec 21, 2024 that may be closed by this pull request
@tsande16 tsande16 changed the title Implement JaCoCo to pass-core Add JaCoCo for Code Coverage Reports in Pass Core Dec 21, 2024
Copy link

sonarqubecloud bot commented Jan 3, 2025

@tsande16 tsande16 marked this pull request as ready for review January 3, 2025 21:24
@tsande16
Copy link
Contributor Author

tsande16 commented Jan 3, 2025

@markpatton @rpoet-jh Where should we put the documentation for this? Perhaps it should have it's own section in the Developer Documentation section, since it's a topic that spans pass-core and pass-support.

Copy link
Contributor

@rpoet-jh rpoet-jh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, Tim. Just a couple comments.

<version>1.14.0-SNAPSHOT</version>
</parent>

<artifactId>jacoco-aggregate-report</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since pass-core-main depends on all other modules already, did you try putting this jacoco pom config (report-aggregate) into the pass-core-main module pom? I wonder if that may be better if it works so that we don't add another module to pass-core? I know there has been talk about wanting to consolidate the modules into one for pass-core.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I'd like to eventually consolidate all the pass-core modules. I don't think the separation has much point. I agree about using pass-core main if possible. In fact I was wondering if it would work in the pass root module to just cover everything.

Copy link
Contributor Author

@tsande16 tsande16 Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpoet-jh I will give this a shot and see what happens. I followed this setup from JaCoCo

From my understanding the report aggregation needs to be it's own separate module. When I originally tried doing this I tried setting the project POM to be the aggregator, but that didn't work. From my reading of the docs, if it was setup in pass-core-main it wouldn't generate a report for pass-core-main, but would only collect from the other submodules and place the aggregated report in pass-core-main.

Copy link
Contributor Author

@tsande16 tsande16 Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markpatton @rpoet-jh This is what happens when I move the aggregation to pass-core-main. It won't create a report for pass-core-main. I've tried playing around with different phases, scopes, with/without the agent in pass-core-main.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for trying. When we consolidate the modules in pass-core, we can revisit. I'm fine leaving it like this for now, @markpatton any objection?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpoet-jh @tsande16 No. Let's go for it.

<packaging>pom</packaging>

<properties>
<maven.compiler.source>23</maven.compiler.source>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass-core uses java 17 atm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. It's interesting that IntelliJ generated that even though my project is set to 17.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpoet-jh I'm reviewing this and it seems like some modules have this property set and other do not. It looks like the majority do not have it set. Should I remove this property altogether?

Copy link
Contributor Author

@tsande16 tsande16 Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the only other POM that has it is in the pass-core-policy submodule. And I'm assuming all this will be inherited from pass-main POM:

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
  <release>17</release>
</configuration>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpoet-jh I'm reviewing this and it seems like some modules have this property set and other do not. It looks like the majority do not have it set. Should I remove this property altogether?

Yeah, I think maven.compiler.source and maven.compiler.target should be removed. Like you said, release will be inherited from the main pom plugin config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

Copy link

sonarqubecloud bot commented Jan 7, 2025

@tsande16
Copy link
Contributor Author

tsande16 commented Jan 7, 2025

@rpoet-jh Following up from our zoom convo from earlier. I tested the question you brought up to see if report aggregation works with tests that exist in another module.

Setup: The FileService tests exist in pass-core-main module. I picked this method which was missing coverage for this one branch:

image

I added a test for the getFileById() exception logic with a missing ID or file name:

@Test
void testGetFileByIdMissingFileId() {
    ResponseEntity<?> response = passFileServiceController.getFileById("", "file.txt");

    assertEquals(400, response.getStatusCodeValue());
    assertEquals("File ID not provided to get a file.", response.getBody());
}

And it now shows it as covered in the JaCoCo Report:

image

@tsande16 tsande16 merged commit 14da9c4 into main Jan 7, 2025
3 checks passed
@tsande16 tsande16 deleted the 1088-setup-jacoco branch January 7, 2025 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setup JaCoCo in PASS Back-end Projects
3 participants