bpanulla
bpanulla

Reputation: 2998

Displaying custom test results in Jenkins Maven job

I just added some Python unit tests to an existing Maven POM but I can't seem to get Jenkins to report the results of the tests when it runs the build.

I'm running nose tests from Maven with the exec-maven-plugin during the "test" phase. The tests run successfully from the Jenkins job and generate an xUnit compatible test report to target/surefire-reports/TEST-nosetests.xml, but Jenkins doesn't pick up on the results.

Interestingly, Maven also reports no tests run before executing the test suite:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- exec-maven-plugin:1.1.1:exec (nosetests) @ server ---
[INFO] ................
[INFO] ----------------------------------------------------------------------
[INFO] Ran 16 tests in 194.799s
[INFO] 
[INFO] OK
[INFO] Registering compile source root /Volumes/Data/workspace/myProject/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

So is this a problem with Jenkins not seeing the results, or with Maven not treating my test suite as actual tests?

Upvotes: 11

Views: 18392

Answers (5)

rajeev
rajeev

Reputation: 59

Try after adding the maven compiler plugin

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <executions>
                <execution>
                    <id>default-testCompile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <encoding>ISO-8859-1</encoding>
                <source>1.8</source>
                <target>1.8</target>
                <useIncrementalCompilation>false</useIncrementalCompilation>
                <testSource>1.8</testSource>
                <testTarget>1.8</testTarget>
            </configuration>
        </plugin>

Upvotes: 1

qacwnfq q
qacwnfq q

Reputation: 345

If you have a more modular Jenkins setup using a free project will not correctly build submodules. If the maven-plugin that generates the reports execution id is e2eTests, then add the following snippet to your pom.xml and the jenkins maven plugin will take care of the rest!

<properties>
    <jenkins.e2eTests.reportsDirectory>target/protractor-reports</jenkins.e2eTests.reportsDirectory>
</properties>

See https://wiki.jenkins-ci.org/display/JENKINS/Building+a+maven2+project

Upvotes: 2

Jim Somerville
Jim Somerville

Reputation: 51

To build upon the answer by bpanulla, if you have tests in more than one sub-directory of your project, you can use a wildcard in the "Test report XMLs" field, such as: **/target/surefire-reports/*.xml

Upvotes: 4

bpanulla
bpanulla

Reputation: 2998

I worked through this problem by using a "free-style software project" in Jenkins rather than the "maven2/3" project.

New Project

Under Build, choose Add build step and configure the project to Invoke top-level Maven targets. I'm using the test target.

Invoke top-level Maven targets

Finally, under Post-build Actions choose Add post-build action of Publish JUnit test result report and point it at the xUnit output from your tests. This option is not available for Maven 2/3 jobs for some reason.

Publish JUnit test result report

Upvotes: 20

khmarbaise
khmarbaise

Reputation: 97349

As you can see in the Tests run output that Maven didn't recognized the tests as tests. Furthermore to see the results in Jenkins you need to check if nope can create junit compatible output result files (which i assume) which can be read by jenkins and of course displayed.

Upvotes: -1

Related Questions