IVR Avenger
IVR Avenger

Reputation: 15494

Java / mvn code coverage AND redundancy?

Have a monolthic app that runs JUnit tests through Surefire and Maven. I see several options out there that will tell me about code coverage, but I'm trying to find something a little different:

Specifically, I'd like to run a mvn build that generates a report (or use an Eclipse plugin that does the same) that will give me a way to see what tests are all pretty much doing the same thing, in addition to the parts of the app that do not have good coverage. Does something like this exist?

Upvotes: 2

Views: 179

Answers (2)

Archimedes Trajano
Archimedes Trajano

Reputation: 41330

To combine with @alexbt answer you can utilize the report you have with Jacoco but plug that report into SonarQube (you can easily install it locally) then get the SonarLint Eclipse plugin that connects to the local SonarQube instance to get the integration you want.

In addition you get copy and paste detection and some redundant code checks. I say some because public methods are never marked as redundant.

Here are an examples of an online report with and without major problems

One bonus is you can centralize the rules for your team.

Upvotes: 1

alexbt
alexbt

Reputation: 17055

I doesn't cover the redundancy part, but for the coverage you may use Jacoco, it's easy to setup with maven:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.6</version>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.7.201606060606</version>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

<reporting>
    <excludeDefaults>true</excludeDefaults>
    <outputDirectory>${project.build.directory}/site</outputDirectory>
    <plugins>

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
        </plugin>

    </plugins>
</reporting>

To generate the report, type mvn site. The reports will be created under target/site.

Upvotes: 2

Related Questions