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

Maven compilation failure but dependencies exist
Deploy Artifact to Nexus from Eclipse
Problems adding xom to Maven project
Maven 3 antrun issue
Is there a way to tell maven to always use the latest _stable_ version of a dependency?
jslint-maven-plugin 1.0.2-SNAPSHOT repository
how to wildcard attach multiple files to an artifact in maven?
SCM-Activity-Plugin and Taglist in SONAR
Maven - Is it possible to specify mirror in pom.xml?
Maven: Show comment/alert in console when a dependency is used (compile/package/…)
Remove filter in web.xml in jetty
How to execute code before TestNG for ie. building up the test suite
Reading a maven settings.xml when building with gradle?
Maven Nested Multi-module project
mvn clean package, I want to copy the created jar to the current directory
Merging configuration values in Maven

Categories

HOME
atom-editor
cookies
comparison
platform-builder
objectgears
q
bookshelf.js
gis
graphql
jsrender
rubygems
indesign
azure-storage-tables
bs4
autotools
append
node-notifier
node-pdfkit
nano-server
rascal
handsontable
msp430
clojurescript
transformation
evopdf
ml
css-animations
bootstrap-tour
php-openssl
facet
applozic
ping
sql-server-2012-express
junit5
bosh
google-cloud-endpoints-v2
xquery-3.0
gtrendsr
column-family
grails-3.1
repo
force-layout
io-redirection
restlet
disassembling
android-browser
vapor
mesos-chronos
spring-security-kerberos
http-redirect
modelmapper
businessworks
smartcontracts
azure-application-gateway
revapi
hls.js
svmlight
aurelia-validation
worker-thread
synchronous
libpng
multi-level
fody
underscore.js-templating
measures
bstr
clang-static-analyzer
fadeout
apachebench
design-by-contract
cloudbees
hsv
kendonumerictextbox
prerequisites
intel-fortran
icu4j
thredds
jmeter-maven-plugin
fouc
php-ci
python-green
qcodo
project-planning
ceil
aapt
marmalade
undefined-reference
bundles
openlaszlo
fmod
floating-point-precision
oam
dexterity
jplaton
batterylevel
eventual-consistency
wsdl-2.0
anonymous-methods
dmoz
dice
newtonscript
getmessage
appconkit
uiviewanimation-curve
hgsubversion
assembly-loading
heartbeat
coercion
android-sdk-2.1
radcombobox
asp.net-mvc-areas
iweb
scripting-languages
defensive-programming
ubuntu-9.04
wsdl.exe
commodore
misv

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App