1

I am pretty new with using Jenkins pipelines and want to test my Jenkinsfiles and libraries. I found the JenkinsPipelinUnit but i am not able to let my tests running.
I am building a microservice with Maven and added the dependency for JenkinsPipelinUnit.

Which maven plugin do I need to add to run the tests? What you have added? Do you have found any good examples or templates?

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
patrick.g
  • 11
  • 2

2 Answers2

2

I was facing the same problem that the tests were not running.

<plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <version>1.6</version>
        <executions>
          <execution>
            <goals>
              <goal>addSources</goal>
              <goal>addTestSources</goal>
              <goal>compile</goal>
              <goal>compileTests</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <sources>
            <source>
              <directory>${project.basedir}/src</directory>
              <includes>
                <include>**/*.groovy</include>
              </includes>
            </source>
            <source>
              <directory>${project.basedir}/vars</directory>
              <includes>
                <include>**/*.groovy</include>
              </includes>
            </source>
          </sources>
          <testSources>
            <testSource>
              <directory>${project.basedir}/src/test/groovy</directory>
              <includes>
                <include>*.groovy</include>
              </includes>
            </testSource>
          </testSources>
        </configuration>
      </plugin>

I am using gmavenplus plugin to run those tests and I had to also add this dependency

<dependency>
  <groupId>org.codehaus.groovy</groupId>
  <artifactId>groovy-all</artifactId>
  <version>2.4.11</version>
  <scope>test</scope>
</dependency>

After adding the two above, I could run the tests. HTH

Rupaleee
  • 75
  • 9
  • seems that the gmavenplus-plugin find my groovy files and also testfiles. They get compiled. How i can print the call stack of the execution like in the JenkinsPipelineUnit is shown ? I tried different maven comands like "mvn clean package" etc. – patrick.g Oct 25 '17 at 11:02
  • @patrick.g, Did you try the printCallStack() method, as mentioned in the [readme](https://github.com/jenkinsci/JenkinsPipelineUnit/blob/master/README.md) – Rupaleee Oct 26 '17 at 09:21
0

As describes in the readme, add the following dependency to the POM:

<dependency>
  <groupId>com.lesfurets</groupId>
  <artifactId>jenkins-pipeline-unit</artifactId>
  <version>1.0</version>
  <scope>test</scope>
</dependency>
StephenKing
  • 36,187
  • 11
  • 83
  • 112
  • I already added the dependency from the Readme. But how I can run my tests? I build with the maven-compiler-plugin and tried "mvn test", but I get no results of the test. – patrick.g Oct 20 '17 at 05:44
  • Do you have other JUnit tests running and executed using the surefire plugin? – StephenKing Oct 20 '17 at 05:57
  • No. The repo only contains pipeline-libraries and a pom.xml. – patrick.g Oct 20 '17 at 06:02
  • Then add the maven-surefire-plugin and make sure that your test class is in the expected path and follows the naming scheme. – StephenKing Oct 20 '17 at 06:06