gpt4 book ai didi

unit-testing - 如何在IntelliJ idea中运行scala ScalaTest?

转载 作者:行者123 更新时间:2023-12-03 11:54:12 25 4
gpt4 key购买 nike

我正在尝试在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

最佳答案

我一直在像这样运行它(但是我确实发现它有点冗长,并且可能会减少):

@RunWith(classOf[JUnitSuiteRunner])
class AuthorisationParserRunAsTest extends JUnit4(AuthorisationParserSpec)
object AuthorisationParserSpec extends Specification {
...
}

关于unit-testing - 如何在IntelliJ idea中运行scala ScalaTest?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4508818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com