【问题标题】:Use jenkins platform to run spock tests in maven project使用jenkins平台在maven项目中运行spock测试
【发布时间】:2019-01-27 21:08:00
【问题描述】:

我创建了包含 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 时,它会检测两个测试类。 我在 git 存储库上部署了项目,并为 maven 项目配置了 jenkins。我推送存储库并为此项目执行作业,但是 jenkins 仅检测到 JUnit 测试的 AppTest 类。 我已更改 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 项目的作业。还有一次詹金斯没有检测到 SpockTest 类。可能是什么问题?

【问题讨论】:

    标签: java maven jenkins spock


    【解决方案1】:

    尝试将 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-28
      • 2014-09-30
      • 2020-12-02
      • 1970-01-01
      • 2018-09-01
      • 2015-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多