如何使用 junit 4 运行 scala 测试?
我无法使用 IDEA 运行以下代码
@Test
class CompanyURLTest extends Assert {
@Test
def test = assert(false);
}
它可以运行,但 J-Unit 说没有可以运行的测试
I can't run following code with IDEA
@Test
class CompanyURLTest extends Assert {
@Test
def test = assert(false);
}
It runs, but J-Unit says that there are not test to run
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我通常将 ScalaTest 与 Junit4 运行器结合使用,以便 Maven 看到并执行我的测试。我喜欢用 Spec/FlatSpec/WordSpec 语义来组织测试。我正在尝试 ShouldMatchers,但我使用 JUnit 太久了,断言对我来说似乎更自然一些。
下面是一个示例:
ScalaTest 文档位于 http://www.scalatest.org/
I generally use ScalaTest in combination with the Junit4 runner so that Maven sees and executes my tests. I like the Spec/FlatSpec/WordSpec semantics for organizing tests. I'm experimenting with the ShouldMatchers but I have used JUnit for so long that asserts just seem a bit more natural to me.
Here's an example:
The ScalaTest docs are at http://www.scalatest.org/
以下对我有用
The following works for me
@org.junit.Test 注释仅适用于方法:@Target({ElementType.METHOD})。
另请记住,测试方法必须返回 Unit。
The @org.junit.Test annotation is only applicable for methods: @Target({ElementType.METHOD}).
Also keep in mind that test methods must return Unit.
尽管已经晚了 - Gradle 网站令人惊讶地有很多很好的教程,展示如何支持 Scala 测试。
https://guides.gradle.org/building-scala-libraries/#review_the_ generated_project_files< /a>
Even though it's late - Gradle site surprisingly has a lot of good tutorials showing how to support Scala tests.
https://guides.gradle.org/building-scala-libraries/#review_the_generated_project_files