简体   繁体   English

使用Grails Maven插件跳过集成测试

[英]Skip Integration Tests Using Grails Maven Plugin

I am using Grails 2.1.0 and Maven 2.1.1. 我正在使用Grails 2.1.0和Maven 2.1.1。 When running the command mvn clean install to generate an EAR file Maven runs the unit tests without any issue, besides running them twice, then runs the integration tests. 当运行命令mvn clean install生成EAR文件时,Maven运行单元测试没有任何问题,除了运行两次,然后运行集成测试。 When it gets to the integration test phase it throws an error Cannot load JDBC driver class 'com.ibm.db2.jcc.DB2Driver' . 进入集成测试阶段时,将引发错误Cannot load JDBC driver class 'com.ibm.db2.jcc.DB2Driver'

Unit and integration tests all pass when run through Grails, and if I build the ear using the -Dmaven.test.skip=true flag it builds without errors and the resulting EAR deploys to the server fine. 通过Grails运行时,单元测试和集成测试全部通过,并且如果我使用-Dmaven.test.skip=true标志来构建耳朵, -Dmaven.test.skip=true它会-Dmaven.test.skip=true构建,并且最终的EAR可以部署到服务器上。

I am upgrading this project from 1.3.7 and that version did not run the integration tests while building. 我正在从1.3.7升级此项目,并且该版本在构建时未运行集成测试。 It also only ran the unit tests once, but from what I've read doing it twice is a known part of the grails-maven plugin. 它也只运行了一次单元测试,但是据我读过两次,这是grails-maven插件的一个已知部分。 Below is the pom that I am using. 下面是我正在使用的pom。

<properties>
    <grails.version>2.1.0</grails.version>
    <slf4j.version>1.6.6</slf4j.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.grails</groupId>
        <artifactId>grails-dependencies</artifactId>
        <version>${grails.version}</version>
        <exclusions>                
            <exclusion>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
            </exclusion>            
        </exclusions>
        <type>pom</type>
    </dependency>

    <dependency>
        <groupId>org.grails</groupId>
        <artifactId>grails-plugin-testing</artifactId>
        <version>${grails.version}</version>
        <scope>test</scope>
    </dependency>

<dependency>
    <groupId>org.grails.plugins</groupId>
    <artifactId>mail</artifactId>
    <version>1.0.1</version>
    <scope>runtime</scope>
    <type>zip</type>
</dependency>

<dependency>
    <groupId>org.grails.plugins</groupId>
    <artifactId>jquery</artifactId>
    <version>1.7.2</version>
    <scope>runtime</scope>
    <type>zip</type>
</dependency>                    

<dependency>
    <groupId>org.grails.plugins</groupId>
    <artifactId>resources</artifactId>
    <version>1.1.6</version>
    <scope>runtime</scope>
    <type>zip</type>
</dependency>                    

<dependency>
    <groupId>org.grails.plugins</groupId>
    <artifactId>webxml</artifactId>
    <version>1.4.1</version>
    <scope>runtime</scope>
    <type>zip</type>
</dependency>    

<dependency>
    <groupId>org.grails</groupId>
    <artifactId>grails-hibernate</artifactId>
    <version>${grails.version}</version>       
</dependency>

<dependency>
    <groupId>org.grails.plugins</groupId>
    <artifactId>hibernate</artifactId>
    <version>${grails.version}</version>
    <scope>compile</scope>
    <type>zip</type>
</dependency>
</dependencies>

<build>
    <pluginManagement />

    <plugins>
        <!-- Disables the Maven surefire plugin for Grails applications, as we have our own test runner -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skip>true</skip>
            </configuration>
            <executions>
                <execution>
                    <id>surefire-it</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>plugins</directory>
                        <includes>
                            <include>**/*</include>
                        </includes>
                        <followSymlinks>false</followSymlinks>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.grails</groupId>
            <artifactId>grails-maven-plugin</artifactId>
            <version>${grails.version}</version>
            <configuration>
                <!-- Whether for Fork a JVM to run Grails commands -->
                <fork>false</fork>
            </configuration>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <goals>
                        <goal>init</goal>
                        <goal>maven-clean</goal>
                        <goal>validate</goal>
                        <goal>config-directories</goal>
                        <goal>maven-compile</goal>
                        <goal>maven-test</goal>
                        <goal>maven-war</goal>
                        <goal>maven-functional-test</goal> 
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I have tried removing the maven-functional-test goal, as well as the entire executions section but run into the same issue either way. 我尝试删除了maven-functional-test目标以及整个执行部分,但是无论哪种方式都遇到相同的问题。 Any thoughts? 有什么想法吗?

I tried using the maven failsafe plugin http://maven.apache.org/surefire/maven-failsafe-plugin/examples/skipping-test.html 我尝试使用Maven故障安全插件http://maven.apache.org/surefire/maven-failsafe-plugin/examples/skipping-test.html

And adding to my pom.xml... 并添加到我的pom.xml中...

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.10</version>
    <configuration>
      <skipITs>true</skipITs>
    </configuration>
</plugin>

But mvn clean install still runs functional-tests. 但是mvn clean install仍在运行功能测试。 Don't know why grails is so stubborn. 不知道为什么grails如此固执。

I'm really just concerned with skipping grails-maven-functional tests, maybe for your case you could try: 我真的只是担心跳过grails-maven功能测试,也许对于您的情况,您可以尝试:

        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <excludes>
                <exclude>**/*IntegrationTest.java</exclude>
            </excludes>
        </configuration>

Finally found a work around to skip grails-maven-functional-test if anyone stumbles upon this article. 终于找到了解决方法,如果有人偶然发现本文,可以跳过grails-maven-function-test。 It requires maven 2.2 or above and adding this to your pom.xml: 它需要maven 2.2或更高版本,并将其添加到pom.xml中:

<plugin>
    <groupId>org.grails</groupId>
    <artifactId>grails-maven-plugin</artifactId>
    <version>${grails.version}</version>
    <extensions>true</extensions>
    <executions>
        <execution>
            <id>default-maven-functional-test</id>
            <phase>integration-test</phase>
            <configuration>
                <skip>true</skip>
            </configuration>
        </execution>
    </executions>
</plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM