Define custom configuration in sbt

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

Let you have this option:

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

How to change testOptions , so it is applied only when the test command has a prefix of some area, for example teamcity:test ?

I expect testOptions to be changed using similar syntax:

 testOptions in Teamcity := ... 

I would also like to know how to define a user area, preferably in a simple *.sbt build, rather than in project/*.scala build.

+8
scala sbt
source share
1 answer

An area can be either a project, or a configuration, or a task. In this case, I think you want to define a user configuration.

using itSettings

Now there is a built-in configuration called IntegrationTest . You can define it in the assembly definition by writing:

 Defaults.itSettings 

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

defining your own configuration

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

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

teamcity: test definition

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

Edit : Mark Harra pointed out to me that there is documentation for this. See Additional test configurations with shared sources .

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

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 running teamcity:test output of Specs2 is displayed without color.

+14
source share

All Articles