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 jetty plugin log4j configuration
Difference between (guava) Resources.getResource(“bddconf.xml”) and properties.getClass().getResourceAsStream(“bddconf.xml”);
Setting up new Maven In eclipse
Specify JRockit or JDK to Maven
How to create the repository (role is repository manager)with nexus
Excluding Maven dependencies
How to integrate maven with cruise control?
Hue won't build due to missing Thrift classes.
Named-Entities Recognition with OpenCalais
How can I copy artifacts with all dependencies from one maven repository into another?
Check maven version in pom.xml
Maven bundles multiple versions of same libraries in WAR
Exclude JAR from maven assembly
How to combine one root level pom to child pom?
Maven version ranges and suffixed versions in IntelliJ Idea
setting maven proxy settings outside of settings.xml

Categories

HOME
multithreading
testng
reflection
fluentd
drivers
google-play
json.net
include
fft
cplex
webstorm
setup-deployment
leon
umd
installshield
serverspec
fancybox
swagger-ui
awesome-wm
google-translate
spring-xd
dax
quicklook
u-sql
export-to-csv
google-apps-marketplace
jsdoc
serilog
interop
shared-hosting
kryo
ml
cloudhub
telerik-reporting
cultureinfo
captiveportal
php-openssl
sparse-matrix
poltergeist
react-css-modules
elasticsearch-ruby
atlassian-crucible
google-cloud-nl
procdump
flink-streaming
frame
pim
y86
mapbox-gl
streamsets
unspecified
az-application-insights
dism
eclipse-gef
slick-3.0
logfiles
termination
zip4j
promela
blogengine.net
rdfs
np-complete
r-forge
sqlbulkcopy
nbconvert
hittest
gnome-shell-extensions
google-cdn
angular-cache
slicknav
elements
trash
paypal-express
autorest
gstreamer-0.10
nessus
oauth2client
rhino-servicebus
asp.net5
wapiti
tcpserver
rtbkit
prerequisites
intel-fortran
eclipse-clp
django-unittest
cakephp-3.1
splash
sysinternals
notify
gwidgets
coldbox
rdtsc
issuu
bitcoinj
php-5.4
navigationservice
elliptic-curve
htmlcleaner
hippomocks
poller
jboss-weld
concurrent-collections
dir
random-seed
sqlperformance
android-hardware
clipper
pvrtc
broken-links
pysimplesoap
removeclass
code-cleanup
external-accessory
xdomainrequest
file-comparison
disclosure
forums
perfect-hash
phonon
genealogy
w3wp
ajax-forms

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