为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

沧海一幻觉 2022-05-25 10:26:21
我创建了由 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.SpockTestInProgressExtensionpom.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 类。可能是什么问题呢?
查看完整描述

1 回答

?
森栏

TA贡献1810条经验 获得超5个赞

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

  • 源代码

    • 时髦的

    • SpockTest.groovy

    • com.jenk...

    • 测试

然后将gmavenplus-plugin(groovy compiler) 和maven-surefire-plugin(test runner) 添加到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

}


查看完整回答
反对 回复 2022-05-25
  • 1 回答
  • 0 关注
  • 259 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号