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

我创建了由 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. 我的项目结构。

http://img1.mukewang.com/628d942e0001657905240319.jpg

文件 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 类。可能是什么问题呢?


沧海一幻觉
浏览 260回答 1
1回答

森栏

尝试将 spock 测试放在groovy文件夹下:源代码时髦的SpockTest.groovycom.jenk...测试然后将gmavenplus-plugin(groovy compiler) 和maven-surefire-plugin(test runner) 添加到pom.xml:&nbsp; &nbsp; <pluginManagement>&nbsp; &nbsp; &nbsp; &nbsp; <plugins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.codehaus.gmavenplus</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>gmavenplus-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>1.6.2</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-surefire-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>2.22.1</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; &nbsp; &nbsp; </plugins>&nbsp; &nbsp; </pluginManagement>&nbsp; &nbsp; ...&nbsp; &nbsp; <plugins>&nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.codehaus.gmavenplus</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>gmavenplus-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <targetBytecode>1.8</targetBytecode>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <warningLevel>2</warningLevel>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>compileTests</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </executions>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-surefire-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; </plugins>为了在 Jenkins 上进行调试,以确保更好地触发预期的测试以防止出现故障:def "one plus one should equal two"() {&nbsp; &nbsp; expect:&nbsp; &nbsp; 1 + 1 == 3}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java