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

452 views Asked by At

I have sbt cross compile platforms with many modules (Android,Scalajs,Native,JVM and shared) I wanted to control the test for each module through build.sbt file by writing a flags to each test eg: I wanted to test the Android module and Jvm only so I set the flags to true and others to false:

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

then I should add some control and checks to those flags and call the test command from sbt shell.

my build.sbt file:

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)

1

There are 1 answers

0
pme On BEST ANSWER

The 2 things I know are:

Using Filters:

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))

From https://stackoverflow.com/a/25853923/2750966

Using Tagging:

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

From ScalaTest Documentation