title: SBT : Override behavior of task "test" to run only tests from default testSource folder, there are multiple test source folders
body: <p>We have standard SBT project with standard directory structure.</p>
  
  <p>The <strong><em>test</em></strong> folder contains all the JUnit tests.</p>
  
  <p>We introduced a new folder <strong><em>othertests</em></strong> and the folder <strong><em>othertests</em></strong> is peer to folder <strong><em>test</em></strong></p>
  
  <p>The <strong><em>othertest</em></strong> folder contains some special test cases. The test classes names in the folder <strong><em>othertest</em></strong> can be easily distinguished from the normal JUnit tests.</p>
  
  <p>Below is my working build.sbt configuration.</p>
  
  <p>I have added the folder <strong><em>othertest</em></strong> in test sources using <code>javaSources in Test</code> SBT task.</p>
  
  <p>We are using <strong><em>activator</em></strong> to run tests and do other stuff.</p>
  
  <p>When I run <code>activator&gt; test</code> I want all tests from the folder <strong><em>test</em></strong>  only to run and I want to run tests from the folder <strong><em>othertests</em></strong> separately.</p>
  
  <p>Questions.</p>
  
  <ol>
  <li>How to override the behavior of test tasks to filter out tests from the folder <strong><em>othertests</em></strong></li>
  <li>Should I create shared modules to run normal junit tests separately and other junit tests separately.</li>
  </ol>
  
  <p>Below is my build.sbt configuration </p>
  
  <pre><code>import java.io.PrintStream
  
  import play.sbt.PlayJava
  import play.twirl.sbt.Import._
  
  name := "Service"
  
  version := "5.1.0"
  
  scalaVersion := "2.11.8"
  
  routesGenerator := InjectedRoutesGenerator
  
  lazy val ContractTest = config("contract") extend(Test)
  
  def contractTestFilter(name: String): Boolean = name endsWith "ContractTest"
  
  def ignoreContractTest(name: String): Boolean = !contractTestFilter(name)
  
  lazy val root = (project in file("."))
    .enablePlugins(PlayJava)
    .configs(ContractTest)
      .settings(
        inConfig(ContractTest) (Defaults.testTasks),
        javaSource in Test := { (baseDirectory in Test) (_ / "contracttest") }.value,
        testOptions in ContractTest := Seq(Tests.Filter(contractTestFilter),Tests.Argument(TestFrameworks.JUnit, "-q", "-v", "-s")),
        testOptions in Test := Seq(Tests.Filter(ignoreContractTest),Tests.Argument(TestFrameworks.JUnit, "-q", "-v", "-s"))
      )
  
  lazy val xyz = taskKey[Unit]("custom task to create loglayout jar file under lib folder")
  
  xyz := {
    LogLayoutJar.build(scalaBinaryVersion.value, streams.value.log)
  }
  
  run := (run in Runtime).dependsOn(xyz).evaluated
  
  javaOptions in Test ++= Seq("-Dconfig.resource=applic.tt.cnf")
  
  libraryDependencies ++= Seq(
    json,
    javaWs,
    "org.mockito" % "mockito-all" % "1.10.19" % Test,
    "org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test,
    "org.easytesting" % "fest-assert" % "1.4" % Test,
    "org.scalactic" %% "scalactic" % "2.2.0",
    "org.jmockit" % "jmockit" % "1.9" % Test,
    "com.portingle" % "slf4jtesting" % "1.0.0" % Test,
    "org.scalacheck" %% "scalacheck" % "1.12.6" % Test
  )
  
  resolvers ++= Seq(
    "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
  )
  
  parallelExecution in Test := runningTestInParallel
  
  testGrouping in Test := groupByModule((externalDependencyClasspath in Test).value,
    (definedTests in Test).value, streams.value.log)
  
  javacOptions ++= Seq(
    "-Xlint:unchecked",
    "-Xlint:deprecation"
  )
  scalacOptions ++= Seq(
    "-feature",
    "-language:implicitConversions",
    "-deprecation"
  )
  
  // Custom tasks //
  val silenceSystemErr = taskKey[Unit]("Replaces System.err with a PrintStream to nowhere.")
  
  silenceSystemErr := {
    System.setErr(new PrintStream(new DevNull))
    println("Messages System.err will not be printed.")
  }
  
  val restoreSystemErr = taskKey[Unit]("Restores the original System.err")
  
  restoreSystemErr := {
    System.setErr(systemErr)
    println("Messages System.err will be printed.")
  }
  </code></pre>
  
  <p>From jenkins we run tests using below command - </p>
  
  <pre><code>bin/activator -Dsbt.log.noformat=true -Denvironment_name=test -DsuppressLogging=true clean silenceSystemErr jacoco:cover
  </code></pre>
  
  <p>Thank You
  Rakesh</p>