New features in JUnit 4.11

JUnit is one of the most popular testing frameworks out there. Version 4.11 has just been released and offers some nice improvements that you shouldn’t miss. Dependencies In older versions of JUnit there were two dependencies .. junit:junit contained an old version of hamcrest and could cause some nasty trouble .. junit:junit-dep just referenced hamcrest the maven way. Now with version 4.11 there is just junit:junit with clean references to hamcrest and junit:junit-dep is relocated to junit:junit. ...

November 18, 2012 · 4 min · 850 words · Micha Kops

Make your Tests more readable with custom Hamcrest Matchers

Everyday we’re writing tests for our software and sometimes we’re in a situation where we’re testing a specific type or object very often. Luckily Hamcrest allows us to create custom matchers by subclassing from a given variety of available matchers. Adding jUnit and Hamcrest First add the dependencies for JUniti and Hamcrest to your project’s pom.xml or alternative build system. <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-all</artifactId> <version>1.3</version> <scope>test</scope> </dependency> </dependencies> ...

October 28, 2012 · 3 min · 610 words · Micha Kops

REST-assured vs Jersey-Test-Framework: Testing your RESTful Web-Services

Today we’re going to take a look at two specific frameworks that enables you to efficiently test your REST-ful services: On the one side there is the framework REST-assured that offers a nice DSL-like syntax to create well readable tests – on the other side there is the Jersey-Test-Framework that offers a nice execution environment and is built upon the JAX-RS reference implementation, Jersey. In the following tutorial we’re going to create a simple REST service first and then implement integration tests for this service using both frameworks. ...

September 5, 2011 · 6 min · 1094 words · Micha Kops

Mocking, Stubbing and Test Spying using the Mockito Framework and PowerMock

Today we’re going to take a look at the Mockito framework that not only does sound like my favourite summer cocktail but also offers nice testing, mocking/stubbing, test-spying features and mock injections. After that we’re going to take a look on how to mock static or final classes by extending Mockito’s capabilities with PowerMock. Prerequisites We don’t need much for the following samples .. Java of course, Maven dependency management and that’s all .. ...

March 27, 2011 · 8 min · 1620 words · Micha Kops