1

有什么方法可以设置 IntelliJ 的 JUnit“运行所有测试”命令来自动获取 Scala Specs2?即删除此片段中的样板注释:

@RunWith(classOf[JUnitRunner])
class MySpec extends Specification

必须记住添加这个非常烦人。

我见过SpecificationWithJUnit,但这也有点像 hack(并且与 不兼容TestKit)。我正在寻找一个 maven/sbt/intelliJ 方面的解决方案。

4

2 回答 2

1

使用 Intellij,您不需要注释来执行您的规范,因为它有自己的 specs2 运行器。我正在使用 IntelliJ 123.100 和最新版本的 Scala 插件(我认为是 82),一切正常(除了这个问题)。

于 2013-02-26T12:53:15.577 回答
0

改用 也许这可以帮助你@RunWith(classOf[JUnitPlatform])JUnitRunner

import org.junit.jupiter.api.{DisplayName, Test}
import org.junit.platform.runner.JUnitPlatform
import org.junit.runner.RunWith
import org.scalatest.{BeforeAndAfterAll, Matchers}
import org.scalatest.junit.JUnitSuite

@RunWith(classOf[JUnitPlatform])
class Junit5Test  extends JUnitSuite with Matchers with BeforeAndAfterAll {

  override def beforeAll: Unit = { println(">>> beforeAll <<< ") }

  @Test
  @DisplayName("Example with JUnitSuite")
  @throws(classOf[RuntimeException])
  def throwsExceptionWhenCalled() {
    println("Запуск теста...")
    assertThrows[RuntimeException] { throw new RuntimeException }
  }

}

build.sbt文件:

val junitJupiter  = "5.2.0"
val junitPlatform = "1.2.0"
libraryDependencies ++= Seq(
  "junit"              % "junit"                   % "4.12" % Test,
  "org.junit.jupiter"  % "junit-jupiter-api"       % junitJupiter % Test,
  "org.junit.jupiter"  % "junit-jupiter-engine"    % junitJupiter % Test,
  "org.junit.jupiter"  % "junit-jupiter-params"    % junitJupiter % Test,
  "org.junit.platform" % "junit-platform-launcher" % junitPlatform % Test,
  "org.junit.platform" % "junit-platform-engine"   % junitPlatform % Test,
  "org.junit.platform" % "junit-platform-runner"   % junitPlatform % Test,
)
于 2018-10-10T10:01:11.007 回答