如何在 IntelliJ idea 中运行 scala ScalaTest?
我正在尝试在 Intellij IDEA(最新的社区构建,带有最新的 Scala 插件)中运行 scala flatspec 测试,但我不断收到“空测试套件”错误。
我尝试使用右键单击时的正常“运行”菜单,但它不起作用。我还尝试创建一个新的 ScalaTest 配置,但运行程序仍然没有进行测试。
我能够将 JScalaTest 与 unit 一起使用,但我真的更喜欢使用 flatspec 语法。
更新:用@RunWith(classOf[JUnitRunner])
注释类也没有帮助
谢谢!
class SampleTestSpec extends FlatSpec with ShouldMatchers {
"test" should "fail" in {
"this" should equal ("that")
}
}
更新:从 ScalaTest 切换到 Spec,解决了问题。我仍然更喜欢 ScalaTest 和 FlatSpec,但这已经足够好了。有效的代码:
import org.specs._
object SampleTestSpec extends Specification {
"'hello world' has 11 characters" in {
"hello world".size must be equalTo(113)
}
"'hello world' matches 'h.* w.*'" in {
"hello world" must be matching("h.* w.*")
}
}
-teo
I'm trying to run a scala flatspec test within Intellij IDEA (latest community build, with latest Scala plugin), but I keep getting "Empty test suite" errors.
I tried using the normal "run" menu on right click, but it does not work. I also tried creating a new ScalaTest configuration, but still the runner is not picking up the tests.
I was able to use JScalaTest with unit, but I'd really prefer to use flatspec syntax.
UPDATE: annotating the class with @RunWith(classOf[JUnitRunner])
does not help either
Thanks!
class SampleTestSpec extends FlatSpec with ShouldMatchers {
"test" should "fail" in {
"this" should equal ("that")
}
}
UPDATE: Switching from ScalaTest to Spec, solved the problem. I still prefer ScalaTest with FlatSpec, but this is good enough. Code that works:
import org.specs._
object SampleTestSpec extends Specification {
"'hello world' has 11 characters" in {
"hello world".size must be equalTo(113)
}
"'hello world' matches 'h.* w.*'" in {
"hello world" must be matching("h.* w.*")
}
}
-teo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
如果 IntelliJ 没有自动选择测试,您可以执行以下操作:
在运行配置中,创建一个 ScalaTest 运行配置,并将其“测试种类”设置为“全部包含在包中”,将“测试包”设置为要运行的包。包含您的测试。
If IntelliJ does not pick up the tests automatically, you can do the following:
In the Run Configuration, create a ScalaTest run configuration and set up its "Test kind" to "All in package" and its "Test Package" to the package that contains your tests.
这对我有用:
编辑配置->测试类型:全包
This worked for me:
Edit configurations -> Test kind: All in package
我一直这样运行它(但是我确实发现它有点冗长,并且可能可以减少):
I've been running it like this (however I do find it a little verbose and it can probably be cut down):
ScalaTest 对所有可能性都有概述;我刚刚注释了所有测试类
ScalaTest has an Overview over all possibilities; I just annotated all test classes with
AFAIK,
JUnitRunner
正是为此。AFAIK, the
JUnitRunner
is exactly for this.只是有点太晚了,但我遇到了同样的问题(“空测试套件”)在闲逛 IDEA 错误跟踪器后,我找到了适合我的案例的解决方案:
我的
scala
版本是2.9.0-1
,scala-test
的版本是2.8.*
。将 scala-test 升级到最新版本(与 scala 相同)后它开始工作。
Just a little too late, but I've met the same problem ("Empty test suite") After hanging around IDEA bug tracker, I've found a solution for my case:
My
scala
version was2.9.0-1
andscala-test
has version2.8.*
.It started to work after upgrading
scala-test
to the newest version (same as a scala).我已经能够在 IntelliJ 中运行 FunSuite 测试,没有任何问题。但是,我在使用 FlatSpec 测试时发现,如果使用 Ctrl+Shift+F10(即运行所有测试),则需要右键单击或将光标定位在实际测试类定义上才能正确执行所有定义的测试并避免令人沮丧的“空测试套件”错误。
I've been able to run FunSuite tests in IntelliJ without any issues. However, what I've found when working with FlatSpec tests, is that you need to right click on or have your cursor located on the actual test class definition if using Ctrl+Shift+F10 (i.e. run all tests) for it to correctly execute all defined tests and avoid the frustrating "Empty test suite" errors.
如果它对任何人有帮助——我刚刚接触 Scala,这是因为我构建测试类的方式。我遇到的
问题是我将测试包装在一个方法中,没有意识到在这种情况下测试需要是裸露的:
In case it helps anyone -- I hit this fresh to Scala and it was because of the way I'd structured my test class. I had
The problem was that I wrapped my test in a method, not realising that in this context the tests need to be bare:
我遇到了“空测试套件”。在 FlatSpec 中运行单独测试时也会出现问题。我将根本原因缩小到行为字符串开头的空格。
前任。在以下代码中,第一个测试将运行,但第二个测试不会运行(如果单独运行)。这是由于行为字符串“not run”开头存在空格所致。如果您将其取下并再次运行,它应该可以工作。
I ran into "Empty test suite." issue while running individual tests in FlatSpec as well. I narrowed down the root cause to a whitespace at the beginning of the in the behavior string.
Ex. In the following code, the first test will run but the second will not (If individually run). This is due to the presence of a whitespace at the beginning of the behavior string " not run". If you take it off and run it again, it should work.
您必须在文件末尾将其设为
Test
,然后在测试配置中单击Run on Sbt
。You have to make it
Test
at the end of the file and clickRun on Sbt
In the test config.