试图让ScalaTest工作:"没有测试运行"做&QUOT时,MVN测试" [英] Trying to get ScalaTest working: "There are no tests to run" when doing "mvn test"
问题描述
编辑:我终于得到它的工作!
它需要的JUnit的组合在pom.xml,在我.scala三个语句:
进口org.junit.runner.RunWith
进口org.scalatest.junit.JUnitRunner@RunWith(classOf [JUnitRunner])
由于某种原因,尝试配置神火使得测试再次停止放送。
我编码的IntelliJ,试图获得通过的Maven( MVN测试
)建设进程中运行一个简单的测试ScalaTest。有没有任何错误,但遗憾的是没有测试运行任。
下面是我的.scala文件:
进口org.scalatest.FunSuite
进口org.scalatest.BeforeAndAfter类ExampleSuite扩展了BeforeAndAfter {FunSuite 之前{
的println(做安装任务......)
} 测试(检查浏览器标题的示例测试){ VAL expected_title =平台公司
VAR actual_title =平台公司
断言(actual_title == expected_title)
} 后{
的println(做拆解工作......)
}
}
下面是Maven的输出:
[信息]扫描项目...
[警告]
JoeTestDemo:罐:同时为JoeTestDemo的有效模式遇到[警告一些问题1.0
【警告】build.plugins.plugin.version'的org.scala工具:Maven的斯卡拉-插件缺失。 @ 42行,21列
[警告]
【警告】强烈建议,因为他们威胁到你构建的稳定来解决这些问题。
[警告]
【警告】因为这个原因,未来的Maven的版本可能不再支持建立这种畸形的项目。
[警告]
[信息]
[INFO] ----------------------------------------------- -------------------------
[INFO]大厦JoeTestDemo 1.0
[INFO] ----------------------------------------------- -------------------------
[信息]
[信息] --- Maven的资源 - 插件:2.4.3:资源(缺省资源)@ JoeTestDemo ---
【警告】使用平台编码(实际上的MacRoman)复制过滤资源,即构建依赖于平台!
[INFO]复制0资源
[信息]
[信息] --- Maven的编译器插件:2.3.2:编译(默认编译)@ JoeTestDemo ---
[INFO]没有可编译 - 所有的类都是最新的
[信息]
[信息] --- Maven的斯卡拉 - 插件:2.15.2:编译(默认)@ JoeTestDemo ---
[INFO]检查斯卡拉的多个版本
[INFO]包括= [** / *。斯卡拉,** / *。java的,]
[INFO]排除= []
[警告]找不到源文件。
[信息]
[信息] --- Maven的资源 - 插件:2.4.3:testResources(缺省testResources)@ JoeTestDemo ---
【警告】使用平台编码(实际上的MacRoman)复制过滤资源,即构建依赖于平台!
[信息]跳到不存在的resourceDirectory /用户/ Joeshaver /项目/ JoeTestDemo / src目录/测试/资源
[信息]
[信息] --- Maven的编译器插件:2.3.2:testCompile(缺省testCompile)@ JoeTestDemo ---
[INFO]没有源编译
[信息]
[信息] --- Maven的斯卡拉 - 插件:2.15.2:testCompile(默认)@ JoeTestDemo ---
[INFO]检查斯卡拉的多个版本
[INFO]包括= [** / *。斯卡拉,** / *。java的,]
[INFO]排除= []
[INFO]没有可编译 - 所有的类都是最新的
[信息]
[信息] --- Maven的万无一失-插件:2.7.2:测试(默认测试)@ JoeTestDemo ---
[INFO]神火报告目录:/用户/ Joeshaver /项目/ JoeTestDemo /目标/万无一失的报表-------------------------------------------------- -----
T E式T小号
-------------------------------------------------- -----
有没有测试运行。结果:测试运行:0,失败:0,错误:0,跳过:0[INFO] ----------------------------------------------- -------------------------
[INFO] BUILD成功
[INFO] ----------------------------------------------- -------------------------
[INFO]总时间:1.368s
[INFO]在表面处理:周二10月23日10点58分30秒PDT 2012
[INFO]最后的记忆:6M / 81M
[INFO] ----------------------------------------------- -------------------------
下面是pom.xml中。我觉得我的Maven插件斯卡拉可能不会是正确的:
<?XML版本=1.0编码=UTF-8&GT?;
<项目的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 GT; JoeTestDemo< /的groupId>
<&的artifactId GT; JoeTestDemo< / artifactId的>
<&版GT; 1.0 LT; /版本> <库>
<&库GT;
<&ID GT; scala-tools.org< / ID>
<名称>斯卡拉工具的Maven2资源库< /名称>
&LT; URL&GT; HTTP://scala-tools.org/repo-releases< / URL&GT;
&LT; /存储库&GT;
&LT; /存储库&GT; &LT; pluginRepositories&GT;
&LT; pluginRepository&GT;
&LT;&ID GT; scala-tools.org&LT; / ID&GT;
&LT;名称&gt;斯卡拉工具的Maven2资源库&LT; /名称&gt;
&LT; URL&GT; HTTP://scala-tools.org/repo-releases< / URL&GT;
&LT; / pluginRepository&GT;
&LT; / pluginRepositories&GT; &LT;依赖和GT;
&LT;&依赖性GT;
&LT;&的groupId GT; org.scala浪&LT; /的groupId&GT;
&LT;&的artifactId GT;的Scala库&LT; / artifactId的&GT;
&LT;&版GT; 2.9.0-1&LT; /版本&GT;
&LT; /依赖性&GT;
&LT;&依赖性GT;
&LT;&的groupId GT; org.scalatest&LT; /的groupId&GT;
&LT;&的artifactId GT; scalatest_2.9.0-1&LT; / artifactId的&GT;
&LT;&版GT; 1.6.1&LT; /版本&GT;
&LT; /依赖性&GT;
&LT; /依赖和GT; &LT;建立&GT;
&LT;&插件GT;
&LT;&插件GT;
&LT;&的groupId GT; org.scala工具&LT; /的groupId&GT;
&LT;&的artifactId GT; Maven的斯卡拉,插件和LT; / artifactId的&GT;
&LT;&执行GT;
&LT;执行与GT;
&LT;目标&GT;
&LT;&目标GT;&编译LT; /目标&GT;
&LT;&目标GT; testCompile&LT; /目标&GT;
&LT; /目标&GT;
&LT; /执行&GT;
&LT; /处决&GT;
&LT;结构&gt;
&LT; sourceDir&GT;的src / main / java的&LT; / sourceDir&GT;
&LT; jvmArgs&GT;
&LT; jvmArg&GT;&-Xms64m LT; / jvmArg&GT;
&LT; jvmArg&GT;&-Xmx1024m LT; / jvmArg&GT;
&LT; / jvmArgs&GT;
&LT; /结构&gt;
&LT; /插件&GT;
&LT; /插件&GT;
&LT; /构建&GT;&LT; /项目&GT;
如果你在Maven的运行,那么你要么必须标注的测试类(ES)
@RunWith(classOf [JUnitRunner])
这需要你有JUnit的作为一个依赖。或者你可以使用 ScalaTest Maven插件(没有用它自己虽然)。
Edit: I finally got it to work!!!
It needed a combination of JUnit in the pom.xml, and three statements in my .scala:
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
For some reason, trying to configure Surefire makes the tests stop running again.
I'm coding in IntelliJ, trying to get a simple ScalaTest test running via a Maven (mvn test
) build process. There aren't any errors, but unfortunately no tests run either.
Here is my .scala file:
import org.scalatest.FunSuite
import org.scalatest.BeforeAndAfter
class ExampleSuite extends FunSuite with BeforeAndAfter {
before {
println("Doing setup tasks...")
}
test("Example test of checking the browser title") {
val expected_title = "Company Platform"
var actual_title = "Company Platform"
assert(actual_title == expected_title)
}
after {
println("Doing teardown tasks...")
}
}
Here's the Maven output:
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for JoeTestDemo:JoeTestDemo:jar:1.0
[WARNING] 'build.plugins.plugin.version' for org.scala-tools:maven-scala-plugin is missing. @ line 42, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building JoeTestDemo 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ JoeTestDemo ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ JoeTestDemo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-scala-plugin:2.15.2:compile (default) @ JoeTestDemo ---
[INFO] Checking for multiple versions of scala
[INFO] includes = [**/*.scala,**/*.java,]
[INFO] excludes = []
[WARNING] No source files found.
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ JoeTestDemo ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Joeshaver/Projects/JoeTestDemo/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ JoeTestDemo ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-scala-plugin:2.15.2:testCompile (default) @ JoeTestDemo ---
[INFO] Checking for multiple versions of scala
[INFO] includes = [**/*.scala,**/*.java,]
[INFO] excludes = []
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ JoeTestDemo ---
[INFO] Surefire report directory: /Users/Joeshaver/Projects/JoeTestDemo/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.368s
[INFO] Finished at: Tue Oct 23 10:58:30 PDT 2012
[INFO] Final Memory: 6M/81M
[INFO] ------------------------------------------------------------------------
Here is the pom.xml. I think my Maven Scala plugin might not be right:
<?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>JoeTestDemo</groupId>
<artifactId>JoeTestDemo</artifactId>
<version>1.0</version>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.9.0-1</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.9.0-1</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDir>src/main/java</sourceDir>
<jvmArgs>
<jvmArg>-Xms64m</jvmArg>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
If you're running on Maven, then you'll either have to annotate your test class(es) with
@RunWith(classOf[JUnitRunner])
This would require you having JUnit as a dependency. Or you could use the ScalaTest Maven Plugin (haven't used it myself though).
这篇关于试图让ScalaTest工作:&QUOT;没有测试运行&QUOT;做&QUOT时,MVN测试&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!