使用Maven运行Groovy测试 [英] Running groovy tests with Maven
问题描述
我有一个文件夹结构如下
ProjectName
- src
- test
- groovy
- java
当我运行命令 mvn clean安装
。它仅运行Java单元测试(位于* src \test\java *目录下),而Groovy测试用例未被调用。看来Groovy没有找到Groovy测试。
请帮助我启用groovy测试用例在Maven的帮助下执行?
pom.xml
< ; project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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>
<包装> jar< / packaging>
< version> 1.0-SNAPSHOT< / version>
< name> ApacheActiveMQSpike< / name>
< url> http://maven.apache.org< / url>
<依赖关系>
< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.11< / version>
< /依赖关系>
< dependency>
< groupId> org.apache.activemq< / groupId>
< artifactId> activemq-all< / artifactId>
< version> 5.8.0< / version>
< /依赖关系>
< dependency>
< groupId> mysql< / groupId>
< artifactId> mysql-connector-java< / artifactId>
< version> 5.1.34< / version>
< /依赖关系>
< dependency>
< groupId> org.codehaus.groovy< / groupId>
< artifactId> groovy-all< / artifactId>
< version> 1.6-beta-2< / version>
< scope> test< / scope>
< /依赖关系>
< /依赖关系>
< / project>
您需要使用 gmaven
插件触发groovy测试
< plugin>
< groupId> org.codehaus.groovy.maven< / groupId>
< artifactId> gmaven-plugin< / artifactId>
< version> 1.0-rc-3< / version>
< extensions> true< / extensions>
<执行次数>
<执行>
<目标>
< goal> testCompile< / goal>
< /目标>
<配置>
< sources>
< fileset>
< directory> $ {pom.basedir} / src / test / java< / directory>
<包括>
< include> ** / *。groovy< / include>
< / includes>
< / fileset>
< / sources>
< / configuration>
< /执行>
< /执行次数>
< / plugin>
好的关于在Maven中运行Groovy测试的文章。
结构应该是
< project>
...
< build>
< plugins>
< plugin>
....
< / plugin>
< / plugins>
< / build>
...
< / project>
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.
Please help me in enabling groovy tests cases Execution with the help of Maven ?
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>
You will need to use gmaven
plugin to trigger groovy tests
<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 article about running Groovy tests in Maven. The structure should be
<project>
...
<build>
<plugins>
<plugin>
....
</plugin>
</plugins>
</build>
...
</project>
这篇关于使用Maven运行Groovy测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!