Fork me on GitHub

Source Code Cross Reference

There are times when we wish to know right away the line number of the source code that caused a test to the fail. The Surefire Report Plugin has the capability to cross reference the source code that made the test fail. In order to activate this feature, the maven-jxr-plugin should be declared in the <reporting> section of the POM along with the maven-surefire-report-plugin. For more details, please read the documentation of the Maven JXR Plugin.

<project>
  [...]
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.20</version>
        <configuration>
          <!-- place your configuration here -->
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jxr-plugin</artifactId>
        <version>2.1</version>
      </plugin>
    </plugins>
  </reporting>
  [...]
</project>

After executing mvn site for site generation, you'll notice that from the Failure Details section of the report, a link is available to redirect you to the source code that caused the failure.

In the figure below the code that caused the failure is com.test.proj.AppTest:36

Failure Details

The link will redirect you to the source by clicking it.

The source

Disabling the Cross Reference Link

To disable the link to the source code, the linkXRef property should be set to false. Alternatively one may simply omit the maven-jxr-plugin from the <reporting> section.