How to get a list of defined tests in sbt project in sbt 0.12?

sbt, scala, scalatest

Solution

`(definedTests in Test)` returns `sbt.TestDefinition`.

val printTests = taskKey[Unit]("something")

printTests := {
  val tests = (definedTests in Test).value
  tests map { t =>
    println(t.name)
  }
}

The above is in sbt 0.13 syntax, but the idea should be same in sbt 0.12.

Problem

How to get a list of test cases (fully qualified names) under current project? The environment is Scala 2.10.2, Sbt 0.12.3 and scalatest 1.9.1

Original source