4
votes

I want to do some sbt custom tasks for running tests (scalatest) by tag. For example: now I can run this in the sbt console:

sbt test-only -- -n UnitTests

I want to run this doing something like

sbt test-unit // or something like that

I also want to do the same by excluding tests

sbt test-only -- -l ExternalTests

to:

sbt test-exclude-external

For accomplishing that I'm trying to create a custom sbt task... but i don't know how to do the -- -l stuff

val testUnit = taskKey[Unit]("Launch unit tests")
testUnit := {
  // sbt test-only -- -n UnitTests
  //(test in Test)
}

It will be useful if also I can run tests by namespace in a custom sbt task:

sbt testOnly integration.actors.*

Can you help me guys? I'm a little newbie with sbt :(

2

2 Answers

4
votes

fullInput does not work well with "in Test". I've finally did this:

val unit = taskKey[Unit]("Launch unit tests")
unit := {
  (testOnly in Test).toTask(s" com.trololo.unit.*").value
}
0
votes

You should be able to use fullInput as in this SO question. Also, possible duplicate of this.