If I write groovy unit tests as classes then maven will run those. But if I write the groovy unit test as a script then maven will ignore them. My pom has dependencies on groovy-all and junit and uses the maven-compiler-plugin. I can run groovy script tests off the command line using GroovyTestSuite where I add the scripts to this and then running it. But would like to do this as part of a maven build. I saw this question Execute external groovy script from Maven but is not quite the same thing. Regards, John
-
Are the tests in the groovy script version using any particular framework (such as Spock)? If not, are they annotated with JUnit annotations, or are you just writing assertions that the script will make when ran? – alexanderific May 04 '16 at 16:24
-
There is no framework (I believe) - I am just using groovy.util.GroovyTestCase and then groovy scripts. As I say, it runs on the command line but maven does not see these as test cases. So is there a plugin that I should be using that will pick up scripts as opposed to classes? – John May 05 '16 at 12:39
1 Answers
Groovy scripts do not compile to .class, and therefore the maven surefire/failsafe plugins for unit/integration testing won't have anything from the testCompile phase to actually run. If you are set on writing them as groovy scripts, you will have to use a different maven plugin to just run the scripts...but likely won't get the JUnit result output you normally would from something like Surefire.
Since GroovyTestSuite is a class in itself, and you want to use Maven to run the tests, I would suggest writing your tests as actual class files instead of scripts. You can also trigger the tests to run from the command line using maven, so that shouldn't hinder your requirement. Going this route will allow you to use additional frameworks in the future (such as Spock!) and also keep you within the confines of traditional maven/JUnit conventions.
Now, if you are indeed set on Groovy scripts as your tests, you could do something similar to this solution and bind the execute goal, configured to point at your groovy script(s), to the test
phase. However, I wouldn't recommend going that route unless you have a very explicit reason to remain in the groovy script realm for your test suites. Writing your test suites as groovy classes instead of scripts shouldn't lose you out any additional groovy features.

- 1
- 1

- 780
- 7
- 16
-
Yes I think you are right - I am best to stick to classes. I do like the idea of writing a simple script but I think the extra hassle outweighs that. Many thanks for the reply. – John May 07 '16 at 05:15