我有一个scala测试类,但是当我试图使用Maven目标“test”运行时,测试没有被运行。我收到Maven消息:“没有要运行的测试。”即使测试位于scala测试类中。我需要添加额外的配置吗?
这是我的包设置:

下面是针对pom文件运行Maven "test“目标的输出:
信息扫描项目..。信息信息大楼scala.maven.test 0.0.1-快照信息也就是说,构建是平台依赖的!复制0资源信息--maven- scala -plugin:2.9.1: Add (scala- C:\workspaces\29112012\scala.maven.test\src\test\scala -first)@ scala.maven.test --信息添加源目录:C:\workspaces\29112012\scala.maven.test\src\test\scala信息添加测试源目录:C:\workspaces\29112012\scala.maven.test\src\test\scala INFO --maven-scala-plugin:2.9.1:编译(scala-C:\workspaces\29112012\scala.maven.test\src\test\scala-first)@scala错误C:\workspaces\29112012\scala.maven.test\src\main\java错误C:\workspaces\29112012\scala.maven.test\src\main\scala错误C:\workspaces\29112012\scala.maven.test\src\test\scala信息编译2个源文件到C:\workspaces\29112012\scala.maven.test\target\classes信息--maven-编译器-插件:2.0.2:编译(默认编译)@scala.maven。所有类都是最新的信息maven编译器插件:2.0.2:编译(默认)@ scala.maven.test所有类都是最新的-maven-资源-插件:2.4.3:testResources(默认-testResources)@ scala.maven.test --使用平台编码(Cp1252实际上)来复制过滤过的资源,也就是说,构建是平台依赖的!复制0资源信息- maven-scala-plugin:2.9.1:testCompile (scala-test- scala.maven.test )@scala.maven.test-错误的C:\workspaces\29112012\scala.maven.test\src\test\java..\scala信息将一个源文件编译成C:\workspaces\29112012\scala.maven.test\target\test-classes信息-maven-编译器-插件:2C:\workspaces\29112012\scala.maven.test\target\surefire-reports ( .0.2:testCompile (default-testCompile) @ scala.maven.test -无编译信息-所有类都是最新的信息-maven-照管--插件:2.7.1:test (default-test) @ scala.maven.test - INFO Surefire报告目录:.0.2:testCompile ,T,E,S,S,,没有测试要运行。 结果: 测试运行: 0,失败: 0,错误: 0,跳过:0 信息信息建立成功信息 2012年INFO最终内存: 7M/17M INFO
这是我的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>scala.maven.test</groupId>
<artifactId>scala.maven.test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.scala-tools
</groupId>
<artifactId>
maven-scala-plugin
</artifactId>
<versionRange>
[2.9.1,)
</versionRange>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.9.0-1</artifactId>
<version>2.0.M5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>发布于 2012-11-30 17:56:39
你的测试类名是什么?Maven可能很挑剔,在默认情况下,我认为它需要类名以'Test‘结尾。
见我以前的文章:Maven won't run tests
发布于 2019-01-19 11:49:46
尽管这是一个非常晚的答复,但我写了它,希望有人可以从中受益,以防他们的scala单元测试没有被发现。一个主要的和沉默的罪魁祸首是测试类的绝对路径。如果路径上的任何目录的名称中都有一个空格,scalatest就不会捡起来。重命名这些目录以成功运行单元测试。
https://stackoverflow.com/questions/13649893
复制相似问题