# Frequently Asked Questions

# General

How do I email a test report?

The following sample code will email a test report if there are any failures:

    <postGoal name="maven-junit-report-plugin:report">
      <j:if test="${maven.test.failure}">
        <j:set var="mailReport" value="${test.mail.report}" />
        <j:if test="${mailReport}">
          <attainGoal name="mail-test-report" />
        </j:if>
      </j:if>
    </postGoal>

    <goal name="mail-test-report">
      ${systemScope.setProperty('javax.xml.transform.TransformerFactory','org.apache.xalan.processor.TransformerFactoryImpl')}
      <ant:style in="${maven.build.dir}/TESTS-TestSuites.xml" out="${maven.build.dir}/junit-report-mail.html" style="${basedir}/overview-summary.xsl" />

      <ant:tstamp/>
      <ant:mail messageMimeType="text/html" messageFile="${maven.build.dir}/junit-report-mail.html"
                subject="[BUILD] JUnit Test Results for ${pom.artifactId}: ${TODAY}" tolist="${pom.build.nagEmailAddress}
    ">
        <ant:from name="Build Master" address="someone@nowhere.com.au" />
      </ant:mail>
    </goal>

Include this in your `maven.xml` file, and set the property `test.mail.report` to `true` for the users that you want to send the mail from (typically just you continuous integration environment).

Note that you have to include Xalan in your dependencies for this particular example (see the main Maven FAQ for more information), and provide the `overview-summary.xsl` file in your project's base directory. An example one is distributed with Ant in `etc/junit-noframes.xsl`.

If you want to receive successful reports, exclude the `<j:if test="${maven.test.failure}">` condition.