Skip to content

Instantly share code, notes, and snippets.

@bvenners
Created December 14, 2013 07:35
Show Gist options
  • Save bvenners/7956533 to your computer and use it in GitHub Desktop.
Save bvenners/7956533 to your computer and use it in GitHub Desktop.
One way to group tags in ScalaTest 2.0
import org.scalatest._
trait TagGroups extends SuiteMixin { this: Suite =>
private val groups: Map[String, Set[String]] =
Map(
"NonUnit" -> Set("org.scalatest.tags.Disk", "org.scalatest.tags.Network"),
"Sluggish" -> Set("org.scalatest.tags.Slow", "org.scalatest.tags.Network")
)
abstract override def run(testName: Option[String], args: Args): Status = {
def expandGroups(set: Set[String]): Set[String] =
set flatMap { tag => groups.getOrElse(tag, Set(tag)) }
val newTagsToInclude: Option[Set[String]] =
for (set <- args.filter.tagsToInclude) yield expandGroups(set)
val newTagsToExclude: Set[String] = expandGroups(args.filter.tagsToExclude)
val newFilter: Filter =
Filter(
newTagsToInclude,
newTagsToExclude,
args.filter.excludeNestedSuites,
args.filter.dynaTags
)
super.run(testName, args.copy(filter = newFilter))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment