Custom sbt task to run tests by tag

人走茶凉 提交于 2019-12-10 20:32:56

问题


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 :(


回答1:


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
}



回答2:


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



来源:https://stackoverflow.com/questions/35863430/custom-sbt-task-to-run-tests-by-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!