1

On a few simple groovy classes I included the junit test in with the class--If you annotate the test methods with @Test (from Junit) and run the main-less class with "groovy MyClass.groovy" it automatically runs the unit tests.

I like this because It really requires zero overhead (no additional files or junk code, just one annotation).

Question is, can I tell it to run a single test method? I tried "groovy MyClass.groovy myMethod" but I didn't really expect that to work. I also tried -Dtest=myMethod which I also didn't have much hope for.

Is there a trick someone knows? I suppose since it is just a .groovy file I could comment out the tests I don't want to run or add a main that calls the various tests, but I'm just wondering if there is a way to leverage this automatic run JUnit tests thing already built into groovy.

Bill K
  • 62,186
  • 18
  • 105
  • 157
  • Is `MyClass.groovy` a proper Junit test case or just groovy script? Please see if this is helpful http://stackoverflow.com/questions/9288107/run-single-test-from-a-junit-class-using-command-line – Rao Dec 09 '16 at 05:25
  • Yes it's a test case and I could run it with the junit runner just like my java tests (I do when I'm in eclipse), the question is could I run it with the groovy runner. Currently it's just "groovy MyClass", to run it with the junit runner I'd have to compile it to a class and then supply a long command line. I could write a batch file but this is something I just use as a one-off now and then and I'd like to know if I could do it "on the fly--like "groovy MyClass.myTest" (Doesn't work either) – Bill K Dec 09 '16 at 07:18
  • Seeking similar: [How to run spock test from command line?](http://stackoverflow.com/questions/41892962/how-to-run-spock-test-from-command-line) – MarkHu Feb 11 '17 at 16:55

0 Answers0