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

JacocoReportAggregationPlugin doesn't work with JvmTestSuitePlugin #21990

Closed
Toldry opened this issue Sep 13, 2022 · 2 comments
Closed

JacocoReportAggregationPlugin doesn't work with JvmTestSuitePlugin #21990

Toldry opened this issue Sep 13, 2022 · 2 comments
Assignees
Labels
a:bug in:jacoco-plugin in:test-suites Work related to the JvmTestSuite Plugin
Milestone

Comments

@Toldry
Copy link

Toldry commented Sep 13, 2022

Applying JacocoReportAggregationPlugin and JvmTestSuitePlugin in concert does not create the testCodeCoverageReport task.

This is opposed to what is described in the documentation:

Automatic report creation
When the project also applies the jvm-test-suite plugin, the following reporting objects are added for each test suite:

testSuiteCodeCoverageReport — JacocoCoverageReport
Creates a container to parameterize the TestSuiteType value.

Expected Behavior

The testCodeCoverageReport task is created.

Current Behavior

The testCodeCoverageReport task is missing.

Context

I was trying to follow the documentation and encountered this bug which caused some confusion.

Steps to Reproduce

Here is a bug replicator I made:
https://github.com/Toldry/jacoco-aggregator-plugin-bug-replicator

To reproduce the bug :

git clone https://github.com/Toldry/jacoco-aggregator-plugin-bug-replicator
cd jacoco-aggregator-plugin-bug-replicator
./gradlew test

You will see the following output:

> Task :plugin:test

JacocoAggregatorPluginBugReplicatorPluginTest > pluginAddsTestCodeCoverageReport(String) > jacoco.aggregator.plugin.bug.replicator.JacocoAggregatorPluginBugReplicatorPluginTest.pluginAddsTestCodeCoverageReport(String)[2] FAILED
    org.opentest4j.AssertionFailedError at JacocoAggregatorPluginBugReplicatorPluginTest.java:22

Your Environment

macOS 12.5.1
Java SDK 8.0.322-librca

Build scan URL:
I cannot provide a build scan.

@jbartok jbartok added in:jacoco-plugin in:test-suites Work related to the JvmTestSuite Plugin and removed to-triage labels Sep 14, 2022
@tresat tresat self-assigned this Sep 14, 2022
@tresat
Copy link
Member

tresat commented Sep 14, 2022

This is behaving as designed.

What's going on here is a little subtle: the JvmTestSuitePlugin will create a task to report on each test suite present in the project, but doesn't actually create any test suites itself. It is usually applied along with the JavaPlugin, which is responsible for creating the default suite.

You can see this behavior clearly by changing your test method in the example to:

    void pluginAddsTestCodeCoverageReport(String option) {
        Project project = ProjectBuilder.builder().build();
        project.getExtensions().getExtraProperties().set("option", option);
        project.getPlugins().apply("jacoco.aggregator.plugin.bug.replicator");

        TestingExtension testing = project.getExtensions().findByType(TestingExtension.class);
        if (null != testing) {
            int numSuites = testing.getSuites().size();
            boolean javaPluginApplied = project.getPlugins().hasPlugin("java");
            assertEquals(javaPluginApplied ? 1 : 0, numSuites);
            if (numSuites > 0) {
                assertNotNull(project.getTasks().findByName("testCodeCoverageReport"));
            }
        }
    }

Which then passes. The failure you were originally seeing is because there weren't any test suites created in the project. No suites, no aggregated report tasks.

@nathan-contino - Maybe we can make this part of the docs clearer somehow?

@tresat tresat closed this as completed Sep 14, 2022
@tresat tresat added this to the 7.6 RC1 milestone Sep 14, 2022
@Toldry
Copy link
Author

Toldry commented Sep 15, 2022

Thank you for addressing this.

I would appreciate changing the docs to clarify 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug in:jacoco-plugin in:test-suites Work related to the JvmTestSuite Plugin
Projects
None yet
Development

No branches or pull requests

3 participants