TestNG vs Spock!

1,873 views
Skip to first unread message

Vidi

unread,
Nov 16, 2011, 6:45:00 PM11/16/11
to Spock Framework - User
Hi, I've been reading some nice things about Spock. Could someone
please point out the differences between Spock & TestNG? What are the
general advantages of using spock over testng?

Thanks in advance!

Vidi

unread,
Nov 16, 2011, 8:44:54 PM11/16/11
to Spock Framework - User
Also, does it support maven projects?

groovybayo

unread,
Nov 17, 2011, 11:19:32 AM11/17/11
to Spock Framework - User
Just from my experience, having used both, I'll make a few comments on
this (p.s. I am far from an expert on both).

Spock

Cons:
- It's built on top of junit, so it is still plagued to an extent by
the same issues Cedric complained about for writing TestNG (http://
beust.com/weblog/2004/02/08/junit-pain/ and
http://beust.com/weblog/2004/08/25/testsetup-and-evil-static-methods/)
. e.g. you can't externalize your test suite in an XML or selective
choose why group of tests to run like you would with TestNG, or set up
test dependencies, to name a few.
- Requires learning groovy. Not a steep learning curve since Groovy is
mainly Java, but on steroids!

Pros:
- Start by reading http://code.google.com/p/spock/wiki/WhySpock
- Since spock test are written in groovy, you harness all the power of
groovy in writing your test cases (this is a BIG win IMO!).
- Mocking is way easier and more expressive than depending on other
third party libraries (if you were using TestNG)
- It's easier and more expressive to read and write
- Extensions are easy to write (if the need arises)
- Power asserts built right in (very very nice, even though you can
get something similar using hamcrest matching library with your TestNG
tests)

I have been using Spock more and more, and really liking it, even
though sometimes I wish it came out of the box with some of the
features I love so much about TestNG.

Cheers

pangea

unread,
Nov 17, 2011, 4:20:44 PM11/17/11
to spockfr...@googlegroups.com
You can SELECTIVELY run spock tests using junit rules (MethodRule). We are successfully using this for a while now. We created custom business feature relevant categories and selectively run them.

Vidi

unread,
Nov 17, 2011, 4:57:51 PM11/17/11
to Spock Framework - User
Thanks so much for your inputs groovybayo & pangea, it was really
useful!

Regards,
Vidi
Reply all
Reply to author
Forward
0 new messages