[英]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时,它将同时检测两个测试类。 我在git仓库上部署了项目,并为maven项目配置了詹金斯。 我推送存储库并执行此项目的工作,但是jenkins仅检测JUnit测试的AppTest类。 我更改了pom.xml并将文件注册添加到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类。 可能是什么问题呢?
尝试将spock测试放在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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.