gpt4 book ai didi

unit-testing - gmaven 没有找到测试

转载 作者:行者123 更新时间:2023-12-01 13:04:45 26 4
gpt4 key购买 nike

嗨,我遇到了一些错误我在 groovy 中有一个非常小的项目。我想用行家。我能够编译我的文件、源代码和测试(我在目标文件夹中有我的 .class)。但是没有执行任何测试。这是我的 pom 文件。

<?xml version="1.0" encoding="UTF-8"?>
<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>gmedia</groupId>
<artifactId>gmedia.api</artifactId>
<name>Gmedia API project</name>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

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

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.2.3</version>
<classifier>jdk15</classifier>
</dependency>

<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.0.2</version>
</dependency>

<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0-rc-5</version>
<executions>
<execution>
<goals>
<!--<goal>generateStubs</goal>-->
<goal>compile</goal>
<!--<goal>generateTestStubs</goal>-->
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<url>http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo</url>
<id>eclipselink</id>
<layout>default</layout>
<name>Repository for library Library[eclipselink]</name>
</repository>
</repositories>

我的 groovy 文件在 src/groovy 和 test/groovy 中

我做错了什么?

顺便说一句,添加此配置时出现编译错误:

<configuration>
<sources>
<fileset>
<directory>${pom.basedir}/src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</fileset>
</sources>
</configuration>

将其添加到 groovy-maven-plugin 时编译我的文件时出现错误

<configuration>
<sources>
<fileset>
<directory>${pom.basedir}/src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</fileset>
</sources>
</configuration>

最佳答案

一方面,您使用的是过时版本的 GMaven。

该插件已移至组 ID org.codehaus.gmaven,当前版本为 1.3:

<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>

此外,您可能需要保持 stub 目标处于事件状态,以便 JUnit 找到您的测试类。

引用此页面:Buildung Groovy Projects with GMaven

更新:

If i define a test to run, it run. but with just mvn clean test, the test are compiled, but not executed

这听起来好像您没有遵循测试类的命名约定。

请参阅本页的第一部分:Inclusions and Exclusions of Tests

关于unit-testing - gmaven 没有找到测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3865988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com