我试图在一个多模块scala项目上执行测试:
Myproject
-module A
-module B模块A是前端,B是带有测试的scala项目。当我进入Myproject/B并执行mvn scalatest:test (或mvn测试)时,它们将很好地执行。然而,如果我尝试从根文件夹,我得到一个错误,阻止我执行一个mvn安装,除非我跳过测试(这是不好的)。
错误是:无法找到或加载主类org.scalatest.tools.Runner。
显然,scalatest在根文件夹中寻找不存在的测试类,它实际上只有主pom.xml,所有源都在子模块A和B中
B也有子模块,但是如果我直接在B目录下运行maven命令,那么那里的测试就会得到执行和发现。实际上,问题是当我在根目录下时。编译甚至sbt-complier:testCompile运行良好,几乎立即失败的是scalatest:test:
[INFO] Myproject.......................................... FAILURE [ 1.108 s]
[INFO] B................................................... SKIPPED
[INFO] A................................................... SKIPPED
[ERROR] Failed to execute goal org.scalatest:scalatest-maven-plugin:2.0.0:test (test) on project Myproject: There are test failures -> [Help 1]从Myproject中的pom.xml中提取:
<project>
<groupId>.....</groupId>
<artifactId>;;;;;;</artifactId>
<packaging>pom</packaging>
<description>Myproject</description>
<version>....</version>
<name>Myproject</name>
<modules>
<module>A</module>
<module>B</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.12</artifactId>
<version>${scalatest.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>com.google.code.sbt-compiler-maven-plugin</groupId>
<artifactId>sbt-compiler-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
<!-- I need to set that to true and override that in the pom.xml from the module B -->
</configuration>
</plugin>
</plugins>
</build>
</project>谢谢。
发布于 2021-01-04 10:57:54
好吧,我想我找到了解决办法。mvn干净测试可以工作,所以我就是这样做的:基本上,在根pom中,我说忽略从父模块开始的配置,模块A中的配置相同,然后修改模块B中的所有内容。我不得不调整一下在最可缩放的目录中使用的目标/id,但是使用根目录或B模块目录中的"mvn测试“可以工作。
准火测试跳过了家长的测试。
Myproject和一个pom.xml,在build/plugins下:
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<id>test</id>
<phase>none</phase>
</execution>
</executions>
</plugin>在构建/插件下的B pom.xml中:
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<skipTests>false</skipTests>
</configuration>
</plugin> https://stackoverflow.com/questions/65523581
复制相似问题