Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

define custom configuration in sbt

Tags:

scala

sbt

I want to set another set of options for running tests in integration server and in dev environment.

Let's have this option:

testOptions := Seq(Tests.Filter(s => Seq("Spec", "Unit").exists(s.endsWith(_))))

How can change the testOptions, so it is only applied, when the test command is prefixed with some scope like teamcity:test?

I expect, that the testOptions would be modified with similar syntax:

testOptions in Teamcity := ...

I also would like to know, how to define the custom scope, preferable in simple *.sbt build, not in project/*.scala build.

like image 321
ryskajakub Avatar asked Sep 13 '13 15:09

ryskajakub


1 Answers

The scope could be either project, configuration, or task. In this case, I think you're looking to define a custom configuration.

using itSettings

There's a built-in configuration called IntegrationTest already. You can define it in your build definition by writing:

Defaults.itSettings

This will use completely different setup from normal tests including the test code (goes into src/it/scala/) and libraries, so this may not be what you want.

defining your own configuration

Using sbt 0.13, you can define a custom configuration as follows in build.sbt:

val TeamCity = config("teamcity") extend(Test)

val root = project.in(file(".")).
  configs(TeamCity).
  settings(/* your stuff here */, ...) 

defining teamcity:test

Now you have to figure out how to define teamcity:test.

Edit: Mark Harrah pointed out to me that there's a documentation for this. See Additional test configurations with shared sources.

An alternative to adding separate sets of test sources (and compilations) is to share sources. In this approach, the sources are compiled together using the same classpath and are packaged together.

putting it all together

val TeamCity = config("teamcity") extend(Test)

val root = project.in(file(".")).
  configs(TeamCity).
  settings( 
    name := "helloworld",
    libraryDependencies ++= Seq(
      "org.specs2" %% "specs2" % "2.2" % "test"
    )
  ).
  settings(inConfig(TeamCity)(Defaults.testTasks ++ Seq(
    testOptions := Seq(Tests.Argument("nocolor"))
  )): _*)

When you run teamcity:test the Specs2 output displays without color.

like image 181
Eugene Yokota Avatar answered Oct 01 '22 12:10

Eugene Yokota