我有sbt交叉编译平台,其中包含许多模块(Android,Scalajs,Native,JVM和共享模块),我想通过在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调用test命令。
我的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)
答案 0 :(得分:1)
我知道的两件事是:
使用过滤器:
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))
来自https://stackoverflow.com/a/25853923/2750966
使用标记:
"The Scala language" must "add correctly" taggedAs(Android) in {
val sum = 1 + 1
assert(sum === 2)
}