java 使用 Maven 运行常规测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27855989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:31:38  来源:igfitidea点击:

Running groovy tests with Maven

javamavengroovy

提问by Shirishkumar Bari

I have a folder structure as below

我有一个文件夹结构如下

ProjectName 
  - src
       - test 
             - groovy
             - java      

When I run command mvn clean install. It only runs Java Unit tests(Located under *src\test\java* directory) while Groovy tests cases are not invoked. It seems Groovy is not finding Groovy tests anymore.

当我运行命令时mvn clean install。它只运行 Java 单元测试(位于 *src\test\java* 目录下),而不会调用 Groovy 测试用例。似乎 Groovy 不再寻找 Groovy 测试了。

Please help me in enabling groovy tests cases Execution with the help of Maven ?

请帮助我在 Maven 的帮助下启用 groovy 测试用例执行?

pom.xml

pom.xml

<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>ApacheActiveMQSpike</groupId>
  <artifactId>ApacheActiveMQSpike</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>ApacheActiveMQSpike</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>

  <dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-all</artifactId>
    <version>5.8.0</version>
  </dependency>

  <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.34</version>
</dependency>

<dependency>
  <groupId>org.codehaus.groovy</groupId>
  <artifactId>groovy-all</artifactId>
  <version>1.6-beta-2</version>
  <scope>test</scope>
</dependency>
</dependencies>

</project>

采纳答案by xyz

You will need to use gmavenplugin to trigger groovy tests

您将需要使用gmaven插件来触发 groovy 测试

<plugin>
  <groupId>org.codehaus.groovy.maven</groupId>
  <artifactId>gmaven-plugin</artifactId>
  <version>1.0-rc-3</version>
  <extensions>true</extensions>
  <executions>
    <execution>
      <goals>
        <goal>testCompile</goal>
      </goals>
      <configuration>
        <sources>
          <fileset>
            <directory>${pom.basedir}/src/test/java</directory>
            <includes>
              <include>**/*.groovy</include>
            </includes>
          </fileset>
        </sources>
      </configuration>
    </execution>
  </executions>
</plugin>

Nice articleabout running Groovy tests in Maven. The structure should be

关于在 Maven 中运行 Groovy 测试的好文章。结构应该是

<project>
  ...
  <build>
    <plugins>
      <plugin>
       ....
      </plugin>
    </plugins>
  </build>
  ...
</project>