【问题标题】:How to test Jenkinsfiles with JenkinsPipelineUnit under Maven如何在 Maven 下使用 JenkinsPipelineUnit 测试 Jenkinsfiles
【发布时间】:2017-10-19 10:53:25
【问题描述】:

我对使用 Jenkins 管道很陌生,想测试我的 Jenkinsfiles 和库。我找到了JenkinsPipelinUnit,但我无法让我的测试运行。
我正在使用 Maven 构建一个微服务,并添加了 JenkinsPipelinUnit 的依赖项。

我需要添加哪个 maven 插件来运行测试?你添加了什么?你有没有找到好的例子或模板?

【问题讨论】:

  • 如果所描述的依赖项不起作用,请发布您的代码和错误消息。

标签: maven unit-testing jenkins jenkins-pipeline jenkins-pipeline-unit


【解决方案1】:

我遇到了同样的问题,测试没有运行。

<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>

我正在使用 gmavenplus 插件来运行这些测试,我还必须添加这个依赖项

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

添加以上两个后,我可以运行测试了。 高温

【讨论】:

  • 似乎 gmavenplus-plugin 找到了我的 groovy 文件和测试文件。他们被编译。我如何打印执行的调用堆栈,如 JenkinsPipelineUnit 所示?我尝试了不同的 maven 命令,例如“mvn clean package”等。
  • @patrick.g,你试过readme中提到的printCallStack()方法吗
【解决方案2】:

readme 中所述,将以下依赖项添加到 POM:

<dependency>
  <groupId>com.lesfurets</groupId>
  <artifactId>jenkins-pipeline-unit</artifactId>
  <version>1.0</version>
  <scope>test</scope>
</dependency>

【讨论】:

  • 我已经添加了自述文件中的依赖项。但是我怎样才能运行我的测试呢?我使用 maven-compiler-plugin 构建并尝试了“mvn test”,但没有得到测试结果。
  • 您是否有其他使用 surefire 插件运行和执行的 JUnit 测试?
  • 没有。该仓库仅包含管道库和 pom.xml。
  • 然后添加 maven-surefire-plugin 并确保您的测试类在预期的路径中并遵循命名方案。
猜你喜欢
  • 2011-07-24
  • 2011-06-13
  • 1970-01-01
  • 2020-06-28
  • 1970-01-01
  • 2012-02-11
  • 2014-08-08
  • 2011-09-10
相关资源
最近更新 更多