我正在尝试从命令行在Groovy中编译和运行单元测试。项目中的包结构未遵循命名约定-这是我目前无法更改的内容。这些类(class)的组织方式为:
src/abc/def/SomeClass.groovy
src/abc/tests/def/TestSomeClass.groovy
当我运行
mvn test
时,消息为:unable to resolve class org.junit.Test
和
unable to resovle class org.junit.Assert
在
src/abc/tests/def/TestSomeClass.groovy
类中。我的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>my-project</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<configuration>
<sources>
<source>
<directory>src</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</source>
</sources>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/Test*.groovy</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
最佳答案
标准的Maven目录布局是这样的:
用于生产:<project>/src/main/groovy/abc/def
对于测试:<project>/src/test/groovy/abc/def
如果按照这种方案安排资源,就不会有问题。
More informations
关于maven - Maven无法解析org.junit.test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45031754/