gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:41:30 25 4
gpt4 key购买 nike

我创建了 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com