java - 使用jenkins平台在maven项目中运行spock测试

标签 java maven jenkins spock

我创建了 Maven 项目,其中包含 junit 和 spock 测试。 两个测试的代码。

public class AppTest 
{
    /**
     * Rigorous Test :-)
     */
    @Test
    public void shouldAnswerWithTrue()
    {
        assertTrue( true );
    }
}

class SpockTest extends Specification  {

    def "one plus one should equal two"() {
        expect:
        1 + 1 == 2
    }

}

在我的本地计算机中,当我运行 mvn test 时,它会破坏两个测试类。 我在 git 存储库上部署了项目,并为 Maven 项目配置了 jenkins。我推送存储库并执行该项目的作业,但是 jenkins 只检测 JUnit 测试的 AppTest 类。 我已更改 pom.xml 并将文件 regadring 添加到 https://github.com/menonvarun/testInProgress-spock-client。 我的项目结构。

enter image description here

文件org.spockframework.runtime.extension.IGlobalExtension的内容

org.imaginea.jenkins.testinprogress.spock.SpockTestInProgressExtension

pom.xml

<repositories>
    <repository>
      <id>repo.jenkins-ci.org</id>
      <url>http://repo.jenkins-ci.org/public/</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.spockframework</groupId>
      <artifactId>spock-core</artifactId>
      <version>1.0-groovy-2.4</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>2.4.7</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.imaginea.jenkins.plugins</groupId>
      <artifactId>testInProgress-spock-client</artifactId>
      <version>0.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

我在jenkins平台上安装了testInProgress插件。之后,我将更改后的 Maven 项目推送到存储库并再次执行 Maven 项目的作业。另一次 Jenkins 没有检测到 SpockTest 类。可能是什么问题?

最佳答案

尝试将 spock 测试放在 groovy 文件夹下:

  • 源代码
    • 测试
      • 绝妙的
        • com.jenk...
          • SpockTest.groovy

然后将gmavenplus-plugin(groovy编译器)和maven-surefire-plugin(测试运行器)添加到pom.xml中:

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.6.2</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
            </plugin>
        </plugins>
    </pluginManagement>

    ...

    <plugins>
        <plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <configuration>
                <targetBytecode>1.8</targetBytecode>
                <warningLevel>2</warningLevel>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compileTests</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
        </plugin>
    </plugins>

用于在 Jenkins 上进行调试,以确保更好地触发预期测试以应对失败情况:

def "one plus one should equal two"() {
    expect:
    1 + 1 == 3
}

关于java - 使用jenkins平台在maven项目中运行spock测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54392888/

相关文章:

java - 如何让javadoc的命令选项/开关在Windows下持久化?

Maven 未拉取以下三个级别的依赖项

java - 架构决策: Generic login application used from multiple projects?

maven - 使用 maven 仅将资源打包为 jar

java - 如何在多个项目中共享.java文件?

java - 如何读取包含转义字符和坐标值的复杂 JSON 字符串

Java缓冲策略失去硬件加速

git - cloudbees 中的 jenkins 远端意外挂断

用于生产部署的 Jenkins

jenkins - 使用多个上游存储库进行测试