包含新的测试目录maven surefire插件 [英] Include new test directory maven surefire plugin

查看:163
本文介绍了包含新的测试目录maven surefire插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现有结构:src / test / java - >所有java单元测试。 Maven surefire插件很容易找到它。
现在,除了这些java单元测试用例之外,我想包含一些常规测试用例,并且我想将它们放在src / test / groovy下。
如何让surefire插件提取这些测试用例?我使用Intellij 12.0 ulitmate版本。

Existing Structure : src/test/java --> All java unit tests. This gets picked up easily by Maven surefire plugin. Now, in addition to these java unit test cases, I want to include some groovy test cases, and I want to put them under src/test/groovy. How do I make the surefire plugin pick up these test cases? I am using Intellij 12.0 ulitmate edition.

 <plugin>
       <artifactId>maven-surefire-plugin</artifactId>
       <configuration>
           <additionalClasspathElements>
               <additionalClasspathElement>../groovy</additionalClasspathElement>
           </additionalClasspathElements>
           <excludes>
                <!-- ignore inner classes -->
                <exclude>**/*$*.java</exclude>

           </excludes>
       </configuration>
       <dependencies>
          <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-junit47</artifactId>
            <version>2.12</version>
          </dependency>
    </dependencies>
   </plugin>

更新:我也试过了build-helper-maven-plugin

Update : I also tried build-helper-maven-plugin

  <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.7</version>
        <executions>
            <!-- States that the plugin's add-test-source goal is executed at generate-test-sources phase. -->
            <execution>
                <id>add-groovy-test-sources</id>
                <phase>generate-test-sources</phase>
                <goals>
                    <goal>add-test-source</goal>
                </goals>
                <configuration>
                    <!-- Configures the source directory of integration tests. -->
                    <sources>
                        <source>src/test/groovy</source>
                    </sources>
                </configuration>
            </execution>
        </executions>
    </plugin>

现在,如果我运行测试目标,我会看到
C:\ Developer \Code\myProj\trunk\ss\src\test\groovy added。

Now, if i run the "test" goal, i see C:\Developer\Code\myProj\trunk\ss\src\test\groovy added.

但我没有看到为groovy文件生成的任何类。

But I dont see any class generated for the groovy file.

最终答案,感谢@khmarbaise,我刚刚升级了版本,并删除了GMaven编译

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>


    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.1.3</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <compilerId>groovy-eclipse-compiler</compilerId>
                <verbose>true</verbose>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-compiler</artifactId>
                    <version>2.8.0-01</version>
                </dependency>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-batch</artifactId>
                    <version>2.1.3-01</version>
                </dependency>
            </dependencies>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
        </plugin>

    </plugins>
</build>


推荐答案

下面的pom正在工作:

The following pom is working:

<project
  xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.soebes.groovy</groupId>
  <artifactId>first-groovy</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <name>Test Groovy Scripting</name>

  <properties>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.codehaus.gmaven.runtime</groupId>
      <artifactId>gmaven-runtime-2.0</artifactId>
      <version>1.5</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>2.0.0</version>
    </dependency>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.8.7</version>
    </dependency>
      <dependency>
        <groupId>org.easytesting</groupId>
        <artifactId>fest-assert</artifactId>
        <version>1.4</version>
      </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <compilerId>groovy-eclipse-compiler</compilerId>
          <verbose>true</verbose>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>2.8.0-01</version>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-batch</artifactId>
            <version>2.0.7-03</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.16</version>
      </plugin>
      <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <version>1.5</version>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.gmaven.runtime</groupId>
            <artifactId>gmaven-runtime-2.0</artifactId>
            <version>1.5</version>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy</artifactId>
            <version>1.8.6</version>
          </dependency>
        </dependencies>
        <configuration>
          <debug>false</debug>
          <verbose>true</verbose>
          <stacktrace>true</stacktrace>
          <defaultScriptExtension>.groovy</defaultScriptExtension>
          <providerSelection>2.0</providerSelection>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>testCompile</goal>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

您可以看到一个完整的工作示例这里。这意味着使用 src / test / groovy src / test / java 下的java单元测试进行groovy测试。

You can see a full working example here. This means having groovy tests under src/test/groovy java unit tests under src/test/java.

这篇关于包含新的测试目录maven surefire插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆