maven - Maven无法解析org.junit.test

标签 maven grails junit

我正在尝试从命令行在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/

相关文章:

eclipse - Maven 没有将 jar 添加到类路径

java - 将使用 Maven 创建的项目上传到 Google App Engine

java cucumber.api.cli.main 命令行用法

java - Maven : No tests were executed

angularjs - 将 Angular 与 Grails 一起使用时出错

jenkins - Junit 测试在 Jenkins Gradle 构建中失败,但不是在本地

使用 TestNG、JSFUnit 2 和 Arquillian 进行自动化测试的 Maven

java - 了解 Intellij 中 Maven 的正确工作流程

unit-testing - 使用Grails时,使非写服务方法静态化有什么好处

Grails4 GORM Domains - 连接表为空