maven


Running Spock unit test along with TestNG in Spring boot maven based project


I'm working with IntelliJ, Spring Boot 1.3, java8 and maven.
We were using TestNG for our unit but when I started using Spock for unit test, I really liked writing test using Spock in Groovy. Here is the folder structure:
src->test->java -> All java based TestNG test lives here
src->test->groovy -> All groovy based Spock test lives here. All test have a suffix of Spec and that's how I've configured surefire plugin to look at those test.
Now when I run these individual test they work just fine. But when I run maven lifecycle command like mvn test or mvn clean install, Spock test does not run even though I have enabled maven compiler and appropriate library.
This is how my pom looks like:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire}</version>
<configuration>
<skipTests>false</skipTests>
<useFile>false</useFile>
<includes>
<include>**/*Spec.*</include>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency> <!-- enables mocking of classes without default
constructor (together with CGLIB) -->
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
I think I'm missing something in plugin which would let maven run Spock test along with TestNG during maven lifecycle command. I think I'm missing trivial thing here. Can can someone give me some pointers here on what should I add in pom or if someone has a sample skeleton project in github which I can look at. Thanks.
I was able to get this working. Here is my updated pom.
I had two problems:
-One to run TestNG and Groovy test as a part of maven test lifecycle. This was made possible by adding dependency in surefire plugin. See below pom.
-After fixing that I had a problem another problem with Intellij where it was complaining about class already exists for my groovy based test. This was due to generated stubs in target folder. For this I had to provide configuration to override those directories as suggested by below link.
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addTestSources</goal>
<goal>testGenerateStubs</goal>
<goal>testCompile</goal>
<goal>removeTestStubs</goal>
</goals>
</execution>
</executions>
<configuration>
<!--<This setting is for intellij bug. This override default location of groovy stubs. for more info
check this : https://youtrack.jetbrains.com/issue/IDEA-153779>-->
<stubsOutputDirectory>${project.build.directory}/generated-groovy-stubs</stubsOutputDirectory>
<testStubsOutputDirectory>${project.build.directory}/generated-groovy-test-stubs</testStubsOutputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire}</version>
<configuration>
<includes>
<include>**/*Spec*.groovy</include>
<include>**/*Test*.java</include>
</includes>
<properties>
<property>
<name>junit</name>
<value>false</value>
</property>
</properties>
<threadCount>1</threadCount>
</configuration>
<!--Below dependency let's surefire play nice with groovy test and testng tests-->
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${version.surefire}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${version.surefire}</version>
</dependency>
</dependencies>
</plugin>
I hope this helps other folks who are trying to run TestNG and Spock test together.

Related Links

Can soapui maven plugin execute multiple projects parallel?
log4j conflict with Apache Storm 1.0.1 and Elasticsearch 5.3.1
Spring Boot batch App - Maven error
Maven deploy to Nexus failed with 502 code when using hostname instead of ip address
Inclusion of scopes when using the Maven scope “import”
Why do i got the error in spark “kafka.cluster.BrokerEnd Point cannot be cast to kafka.cluster.Broker”
Drools Swam - Maven Build Issue in Cent OS Server (Abroad)
want to run exec-maven-plugin when spring-boot running
excludesList parameter usage in versions:update-properties
Spring boot - JPA with QueryDSL custom query implementation - entity not mapped error
Idea's cmd and git bash don't see mvn command
jenkins - version placeholder from previous build POM
Can JRebel reload Kotlin classes when they are used by kotlin-maven-plugin plugin on maven?
Incremental build with maven#3.3.3 in multi module project
Maven: execute cli command based on profile (if else)
List the remote repositories used in gradle project by parsing build.gradle from a maven project

Categories

HOME
twitter
osgi
hive
magnific-popup
gremlin
deezer
reserved
relative-path
lodash
electron
vmware
paw-app
amazon-ecs
twitter-bootstrap-4
webpack-2
google-project-tango
installshield
basic
kibana-4
imacros
postgres-xl
tostring
ab-testing
beyondcompare
samoa
xlsxwriter
one-hot-encoding
autoconf
ehcache
pass-by-reference
buildbot
qhull
maxmind
saas
log4js-node
google-cloud-nl
iframe-resizer
key-value-observing
webtest
vsts-build-task
wpf-controls
bitbucket-pipelines
lto
uft-api
android-fingerprint-api
splice
websphere-mq-fte
angular-resource
flickr-api
osx-mavericks
typescript1.8
lift-json
watchconnectivity
android-textview
gstreamer-0.10
connect-by
blackberry-10
dlna
asp.net5
tcpserver
rtbkit
wso2cloud
mutation-observers
drawbitmap
responsive-images
service-accounts
myo
sniffer
coldbox
xcode-6.2
preferences
openexr
contenttype
rebol3
jboss-weld
app42
listings
ora-00911
seed
spring-validator
sabredav
mt
funscript
bluepill
gdata-api
automount
ocx
data-loss
psi
self-extracting
telerik-scheduler
preference
swing-app-framework
boost-smart-ptr
genealogy

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App