代码之家  ›  专栏  ›  技术社区  ›  maciejka

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

  •  0
  • maciejka  · 技术社区  · 7 年前

    我创建了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测试时,它会检测两个测试类。 我在git存储库上部署了项目,并为maven项目配置了jenkins。我推送存储库并执行该项目的作业,但jenkins只检测JUnit测试的AppTest类。 https://github.com/menonvarun/testInProgress-spock-client . 我的项目结构。

    enter image description here

    文件org.spockframework.runtime.extension.IGlobalExtension的内容

    org.imaginea.jenkins.testinprogress.spock.SpockTestInProgressExtension
    

    <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类。有什么问题吗?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Dmytro Maslenko    7 年前

    试着进行斯波克测试 groovy 文件夹:

    • src
      • 测验
          • 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>
    

    def "one plus one should equal two"() {
        expect:
        1 + 1 == 3
    }