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

Use jenkins platform to run spock tests in maven project

我创建了由 junit 和 spock 测试组成的 maven 项目。 两个测试的代码。

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 时,它检测到两个测试 classes。 我在 git 存储库上部署了项目,并为 maven 项目配置了 jenkins。我为这个项目推送存储库并执行作业,但是 jenkins 只检测到 AppTest class 用于 JUnit 测试。 我已经更改了 pom.xml 并将文件 regadring 添加到 https://github.com/menonvarun/testInProgress-spock-client。 我的项目结构。

文件内容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 class。可能是什么问题?

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

  • 来源
    • 测试
      • 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
}