Mat*_*ari 21 unit-testing scala intellij-idea scalatest
我正在尝试在Intellij IDEA(最新的社区版本,最新的Scala插件)中运行scala flatspec测试,但我不断收到"空测试套件"错误.
我尝试右键单击使用正常的"运行"菜单,但它不起作用.我也尝试过创建一个新的ScalaTest配置,但是跑步者仍然没有接受测试.
我能够将JScalaTest与单元一起使用,但我更喜欢使用flatspec语法.
更新:注释类@RunWith(classOf[JUnitRunner])并没有帮助
谢谢!
class SampleTestSpec extends FlatSpec with ShouldMatchers {
"test" should "fail" in {
"this" should equal ("that")
}
}
Run Code Online (Sandbox Code Playgroud)
更新:从ScalaTest切换到Spec,解决了问题.我仍然更喜欢使用FlatSpec的ScalaTest,但这已经足够了.有效的代码:
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.*")
}
}
Run Code Online (Sandbox Code Playgroud)
-TeO
小智 16
如果IntelliJ没有自动获取测试,您可以执行以下操作:
在"运行配置"中,创建一个ScalaTest运行配置,并将其"测试类型"设置为"All in package",将其"Test Package"设置为包含测试的软件包.
我一直这样运行它(但是我确实发现它有点冗长,并且可能可以减少):
@RunWith(classOf[JUnitSuiteRunner])
class AuthorisationParserRunAsTest extends JUnit4(AuthorisationParserSpec)
object AuthorisationParserSpec extends Specification {
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23941 次 |
| 最近记录: |