danowar
danowar

Reputation: 675

I can't get automatic unit testing to work with Jenkins and Sonar (and finally with Maven)

I don't know if I understand something wrong. I' trying to get automatic unit testing to work in my project.

I made a Eclipse Plugin Project and converted it into a Maven Project. I made a JUnit test case class testing the only class in the project. I placed every code in the Maven way (i.e. src/main/java main code and src/test/java test code).

I placed the test class in src/test/java in a package called pluginmaventest.actions .

The test case automatically fails if started in Eclipse as a JUnit test.

I shared the project in a SVN repository and made a Jenkins job (Maven 2/3 project). I added the JUnit dependency to the pom.xml and all necessary tycho dependencies.

The project build is successful. Shouldn't it be failing because my JUnit test fails?

I tried

mvn clean install

and

mvn test

as goals. I even tried to use -Dtest=SomeClassTest. The build never fails.

This obviously means that the unit test is neither compiled nor performed, doesn't it?

I'm just trying to get a grip with Jenkins, Sonar and unit tests. My momentary goal is to get unit tests running with Jenkins, and then try to get code analysis and test coverage running with Sonar, which is integrated into Jenkins. Is there a comprehensive and understandable tutorial or how-to on the web?

ADDENDUM:

Here is my whole project pom.xml. (without surefire maven didn't produce any output, either)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://
maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test.maven.plugin</groupId>
<artifactId>pluginmaventest</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Bla</name>
<packaging>eclipse-plugin</packaging>

<properties>
    <tycho-version>0.13.0</tycho-version>
</properties>
<repositories>
    <repository>
      <id>indigo</id>
      <layout>p2</layout>
      <url>http://download.eclipse.org/releases/indigo/</url>
    </repository>
</repositories>
<dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-maven-plugin</artifactId>
        <version>${tycho-version}</version>
        <type>maven-plugin</type>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
    </dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.11</version>
    </plugin>
  </plugins>
</pluginManagement>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
  </plugin>
  <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-maven-plugin</artifactId>
        <version>${tycho-version}</version>
        <extensions>true</extensions>
    </plugin>
    <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>target-platform-configuration</artifactId>
        <version>${tycho-version}</version>
        <configuration>
            <resolver>p2</resolver>
            <environments>
                <environment>
                    <os>linux</os>
                    <ws>gtk</ws>
                    <arch>x86</arch>
                </environment>
                <environment>
                    <os>linux</os>
                    <ws>gtk</ws>
                    <arch>x86_64</arch>
                </environment>
                <environment>
                    <os>win32</os>
                    <ws>win32</ws>
                    <arch>x86</arch>
                </environment>
                <environment>
                    <os>win32</os>
                    <ws>win32</ws>
                    <arch>x86_64</arch>
                </environment>
                <environment>
                    <os>macosx</os>
                    <ws>cocoa</ws>
                    <arch>x86_64</arch>
                </environment>
            </environments>
        </configuration>
    </plugin>
</plugins>

Upvotes: 0

Views: 3037

Answers (3)

jsievers
jsievers

Reputation: 1853

check your project setup against the working demo example with tests: http://git.eclipse.org/c/tycho/org.eclipse.tycho.git/tree/tycho-demo/itp01

Upvotes: -1

digitaljoel
digitaljoel

Reputation: 26584

You should make sure that the build runs the tests locally when you build with maven. If that is the case, then it could be that Jenkins isn't getting the updates from SVN. Configure it to checkout rather than update for the build and see if it now runs the tests. If that doesn't cause the failure (or at least cause the tests to run) then have a look at the console output from the Jenkins build and see what clues are in there for your build.

Upvotes: 1

recampbell
recampbell

Reputation: 1247

Jenkins should mark the build as UNSTABLE (yellow ball) if a test fails. Most people consider this superior to a FAILED status (red ball) because it provides more information. You ought to be able to see a graph of test passes/failures for all jobs on the job detail page.

If you would like to see what a failure looks like (say you want a sanity check), you could try committing uncompilable code, or calling invalid Maven goals.

Upvotes: 0

Related Questions