Using Spock to test Groovy AND Java applications | zeroturnaround.com
When it comes to Java, most developers either use JUnit or TestNG. JUnit is the established de-facto solution, while TestNG attempts to offer additional features needed for Enterprise applications.
For excellent unit tests, you also need to looking into mocking as I explained in one of my previous posts. For this need Mockito comes to the rescue and offers powerful mocking abilities to your unit tests.
So is JUnit/Mockito the best possible combination?
For this post, I took some time to play around with another testing framework called Spock. Spock is a test framework for Groovy applications, however as a Java developer I wanted to know how well it did at testing Java code as well.
Spock is stable and solid (it has been around since 2008), even if at the time of this writing, it has not even reached its 1.0 release. But it has some interesting features that you might find beneficial for testing your Java & Groovy apps, like how Spock can perform both assertion checking (like JUnit) and Mocking (like Mockito) at the same time. So, now you have two libraries in one! How cool is that?
Getting Started with Installing Spock
Unfortunately, the reference documentation for Spock is not yet ready. So the Getting started page in the old Wiki is not up-to-date, since most of the effort is going to the new Documentation.
There are multiple ways to use Spock. Some of them are:
- As part of a Gradle build (which is Groovy's build tool of choice)
In a Maven project (which can have both Java and Groovy code)
- In an Eclipse project
- On the web with no installation at all. See the Spock console.
The old Wiki still contains descriptions about old versions of both Spock and Groovy. In the end, I chose the Eclipse way.
There is a Groovy plugin on the Eclipse MarketPlace that adds support (syntax highlighting, code completion) for Groovy scripts, so once you have it installed you are good to go. Protip: Make sure that you select the "monospace font" option in Eclipse!
Read full article from Using Spock to test Groovy AND Java applications | zeroturnaround.com
No comments:
Post a Comment