Hello, we are using jacoco to calculate codecovera...
# general
t
Hello, we are using jacoco to calculate codecoverage at test phase. For our unit tests, it is working correctly, however i dont know if pact test can be count toward code coverage given that consumer test is basically a unit test and our provider test is running with junit 5 although they run in verify phase. Has anyone tried reporting pact test coverage with jacoco?
m
Might be best asking in #C9UN99H24
What's the actual issue though? My understanding is that it simply instruments code run paths
☝️ 1
That should be agnostic to pact or any other testing
t
Yes, there should be no issues.
You would just run your unit tests like normal, and then look at the coverage
t
my bad, the test result actually reported by jacoco, however since i am using Feign to call provider, there is no implementation code, only an interface class thus jacoco did not see any code get covered when running consumer test. On the provider side, it does report controller, and some services classes get tested, however, due to my jacoco merge config, the result was not merged to the report generated at test phase. I still need to adjust my jacoco config.
t
Yep. This sounds like a jacoco problem rather than a pact problem
a
I have similar issue with @PactVerifyProvider(CONSUMER_INTERFACE) String verifyMessageForInterface() that somehow reduces curremt jacoco ratio. I'm looking at jacoco pom.xml configuration to exclude PactVerificationTest.class in provider and no luck yet. Just wonder if somebody knew the solution.
t
I named my provider tests as *.PPT so that they are not pickup by surefire. Then i make a profile to run only provider tests and generate jacoco report for them. Here is my profile: <profile> <id>provider-pact-test</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M4</version> <executions> <execution> <id>default-test</id> <phase>test</phase> <goals> <goal>test</goal> </goals> <configuration> <!-- Donot run any normal unit test --> <excludes> <exclude>**/Test*.java</exclude> <exclude>**/*Test.java</exclude> <exclude>**/*Tests.java</exclude> <exclude>**/*TestCase.java</exclude> </excludes> </configuration> </execution> <execution> <id>integration-test</id> <phase>integration-test</phase> <goals> <goal>test</goal> </goals> <configuration> <excludes> <exclude>**/Test*</exclude> <exclude>**/*Test</exclude> <exclude>**/*Tests</exclude> <exclude>**/*TestCase</exclude> </excludes> <includes> <include>**/*PPT</include> </includes> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.6</version> <executions> <execution> <id>pre-integration-test</id> <phase>pre-integration-test</phase> <goals> <goal>prepare-agent</goal> </goals> <configuration> <destFile>${project.build.directory}/jacoco-output/provider-pact-test.exec</destFile> <propertyName>surefireArgLine</propertyName> </configuration> </execution> <execution> <id>post-integration-test</id> <phase>post-integration-test</phase> <goals> <goal>report</goal> </goals> <configuration> <dataFile>${project.build.directory}/jacoco-output/provider-pact-test.exec</dataFile> <outputDirectory>${project.build.directory}/jacoco-provider-pact-test-coverage-report</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile>
by pasting it here i just realized, i can just put skipTest in the test phase instead of excluding 😄 *Test.
a
Thanks to @Thai Le for sharing. I realized the suggestion from @Matt (pactflow.io / pact-js / pact-go) therefore I added my non-UT standalone provider PactVerifyProvider to an existing UT which helps. My actual issue is surefire version 3.0.0-M4 which can see my pact tests but not other existing UT which reduces CC ratio to 0.0.
t
i am running build on CI/CD and i have 4 different jobs which runs 4 different kinds of test: unit tests, db integration tests, pact consumer tests and pact provider tests. Each job compiles and runs the tests in a separated docker container. Thus I have to use a different profile (the one I shared is for provider test) for each job to run only one kind of test. At the end of each job, there is one .exec file generated so I gather them and the compiled classes and run the jacoco:merge (in a different job). I have 3 profiles (integration, consumer-pact-test and provider-pact-test) that are similar to the one i shared, the default is the unit test that i configure in the build section: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M4</version> <configuration> <argLine>${surefireArgLine}</argLine> <redirectTestOutputToFile>true</redirectTestOutputToFile> <reportsDirectory>${project.build.directory}/test-reports</reportsDirectory> </configuration> </plugin> <!-- Code Coverage report generation --> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.6</version> <executions> <execution> <id>pre-unit-test</id> <goals> <goal>prepare-agent</goal> </goals> <configuration> <destFile>${project.build.directory}/jacoco-output/unit-test.exec</destFile> <propertyName>surefireArgLine</propertyName> </configuration> </execution> <execution> <id>post-unit-test</id> <phase>test</phase> <goals> <goal>report</goal> </goals> <configuration> <dataFile>${project.build.directory}/jacoco-output/unit-test.exec</dataFile> <outputDirectory>${project.build.directory}/jacoco-unit-test-coverage-report</outputDirectory> </configuration> </execution> <execution> <id>pre-integration-test</id> <phase>pre-integration-test</phase> <goals> <goal>prepare-agent</goal> </goals> <configuration> <destFile>${project.build.directory}/jacoco-output/integration-test.exec</destFile> <propertyName>surefireArgLine</propertyName> </configuration> </execution> <execution> <id>post-integration-test</id> <phase>post-integration-test</phase> <goals> <goal>report</goal> </goals> <configuration> <dataFile>${project.build.directory}/jacoco-output/integration-test.exec</dataFile> <outputDirectory>${project.build.directory}/jacoco-integration-test-coverage-report</outputDirectory> </configuration> </execution> <execution> <id>merge-all-test-coverage</id> <goals> <goal>merge</goal> </goals> <configuration> <fileSets> <fileSet> <directory>${project.build.directory}/jacoco-output/</directory> <includes> <include>*.exec</include> </includes> </fileSet> </fileSets> <destFile>${project.build.directory}/jacoco-merged.exec</destFile> </configuration> </execution> </executions> </plugin>
hope it helps