1

I'm trying to support running tags/groups of tests on the Maven commandline. I think I have the correct syntax setup in my .scala file (see below), but I'm unsure how to actually execute on the commandline. Examples on the web are mostly in Java.

I want to be able to do something like mvn clean test -Dtags:SlowTest,DbTest to run all the tests tagged as "slow" and "db".

I've seen Surefire pom.xml examples out there, but I'm not sure how I'd then tag the Surefire groups in my test code itself.

Ideas?

import org.junit.experimental.categories.Category
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.Tag

class SlowTest extends Tag("com.mycompany.tags.SlowTest")
class DbTest extends Tag("com.mycompany.tags.DbTest")

@RunWith(classOf[JUnitRunner])
@Category(Array(classOf[SlowTest], classOf[DbTest]))
class FunSuiteTest extends FunSuite with DemoHelpers {
  test("DemoTest1") {
Aaron Shaver
  • 484
  • 3
  • 7
  • 18
  • Why don't you use [scalatest-maven-plugin](http://www.scalatest.org/user_guide/using_the_scalatest_maven_plugin)? It supports tags to include. – maba Oct 31 '12 at 20:28
  • That's exactly what I'm doing, I just don't know how to refer to tags on the Maven commandline. – Aaron Shaver Oct 31 '12 at 20:39

2 Answers2

1

If you are using the scalatest-maven-plugin you should be able to do something like this:

mvn -DtagsToInclude=SlowTest,DbTest clean test
maba
  • 47,113
  • 10
  • 108
  • 118
  • 1
    Good idea, but that command line doesn't work for me. It ran all the tests. :-/ – Aaron Shaver Oct 31 '12 at 20:53
  • It looks like I'm using a slightly different plug-in: net.alchim31.maven scala-maven-plugin 3.1.0 compile testCompile – Aaron Shaver Oct 31 '12 at 20:57
  • The link describes how to setup the plugin. I also gave you an answer here: http://stackoverflow.com/a/13044449/1350762 – maba Oct 31 '12 at 21:00
  • That plugin you refer to is just the scala plugin, not scalatest. You seem to use JUnitRunner and I don't think the scalatest-maven-plugin works well in that combination. – maba Oct 31 '12 at 21:02
  • Yes, I think your setup and mine are too different. I am indeed using JUnit's runner. Your pom.xml is setup to use the Scala test runner (I just tried it). I will need to figure out how to do grouping/tagging in JUnit I think. – Aaron Shaver Oct 31 '12 at 21:05
  • But in that other question you are hinting that you want to avoid using JUnit. My solution does that. – maba Oct 31 '12 at 21:15
  • Yes. It's since changed and I'm using JUnit. It looks like `maven-surefire-plugin` supports test groups, but now I'm not sure how to specify those groups in my .scala code. – Aaron Shaver Oct 31 '12 at 21:23
  • [This SO answer](http://stackoverflow.com/a/7237355/1350762) seems to deal with grouping of tests. Hope that helps. Good luck! – maba Oct 31 '12 at 21:31
-1

I might suggest that if you want to do some test in Scala, why dont you try using

SCALA TEST

it is good and easy to use.