我如何 运行 在 sbt 交叉编译平台中进行特定的 scala 测试?

How do I run specific scala-test in sbt cross compile platforms?

我有很多模块(Android、Scalajs、Native、JVM 和共享)的 sbt 交叉编译平台我想通过 build.sbt 文件通过写入标志来控制每个模块的测试每个测试例如:我只想测试 Android 模块和 JVM,所以我将标志设置为 true,将其他标志设置为 false:

//Testing flags
val androidQuickTest = true
val jvmQuickTest = true
val scalaJsQuickTest = false
val nativeQuickTest = false
val sharedQuickTest = false

然后我应该对这些标志添加一些控制和检查,并从 sbt shell.

调用测试命令

我的 build.sbt 文件:

name := "CrossCompilePlatforms"

version := "0.1"

import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

val sharedSettings = Seq(scalaVersion := "2.11.12",
  libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"
)

val commonAndroidSettings = Seq(
  scalaVersion := "2.11.8",
  sbtVersion := "0.13.13",
  scalacOptions += "-target:jvm-1.7",
  javacOptions ++= Seq("-source", "1.7", "-target", "1.7"),
  exportJars := true
)

val commonNativeSettings = Seq(
  scalaVersion := "2.11.12",
  nativeLinkStubs := true,
  libraryDependencies += "org.scalatest" % "scalatest_native0.3_2.11" % "3.2.0-SNAP10"
)

lazy val myProject =

  crossProject(JSPlatform, JVMPlatform)
    .crossType(CrossType.Full)
    .settings(sharedSettings)
    .settings(libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test")
    .jsSettings(libraryDependencies += "org.querki" %%% "jquery-facade" % "1.2")
    .jvmSettings()

lazy val myProjectJS = myProject.js.dependsOn(myProjectShared)
lazy val myProjectVM = myProject.jvm.dependsOn(myProjectShared)

lazy val myProjectNativeWin10 = project.in(file("./myProject/nativeWin10"))
  .settings(sharedSettings)
  .dependsOn(myProjectShared)

lazy val myProjectNativeUbuntu18 = project.in(file("./myProject/nativeUbuntu18"))
  .enablePlugins(ScalaNativePlugin)
  .settings(commonNativeSettings)

lazy val myProjectShared = project.in(file("./myProject/shared"))
  .settings(sharedSettings)

lazy val myProjectAndroid = project.in(file("./myProject/android"))
  .settings(commonAndroidSettings: _*)
  .settings(
    target := baseDirectory.value / ".android" / "target"
  )
  .dependsOn(myProjectShared)

我知道的两件事是:

使用过滤器

lazy val FunTest = config("fun") extend(Test)

def funTestFilter(name: String): Boolean = ((name endsWith "ItTest") || (name endsWith "IntegrationTest"))
def unitTestFilter(name: String): Boolean = ((name endsWith "Test") && !funTestFilter(name))

lazy val root = project in file(".") configs(FunTest) settings( inConfig(FunTest)(Defaults.testTasks) : _*)

testOptions in FunTest := Seq(Tests.Filter(funTestFilter))

testOptions in Test := Seq(Tests.Filter(unitTestFilter))

来自

使用标记:

"The Scala language" must "add correctly" taggedAs(Android) in {
  val sum = 1 + 1
  assert(sum === 2)
}

来自ScalaTest Documentation