Spring Data MongoDB – Unit Testing using in memory Fongo

This post is about unit testing spring data mongodb using in-memory java implementation of Mongo called Fongo. Complete source code is in github. https://github.com/sanjuthomas/spring-data-mongodb Tools and Libraries used. Fongo (1.1.2) Spring Data MongoDB (1.2.2.RELEASE) Mongo java driver (2.11.0) Junit (4.8.1) Spring Test (3.2.4.RELEASE) No SQL Unit MongoDB (0.7.7) Java 7 We will save and load […]
Continue reading…

 

Unit Testing Spring MVC REST Controllers

Today’s post is about unit testing Spring MVC REST controllers using MockMvcBuilders standalone setup. Complete source code for this post can be cloned from github. Libraries Used pom.xml Controller Code Response Model Object Controller Test Class test-servlet-context.xml Since we are interested to get the response in JSON format we are using Jackson Message Converter.
Continue reading…

 

Spring MVC REST — Unit Testing Post Request

This post is about unit testing Spring MVC REST controller using Spring test framework MockMvcBuilders and junit. The complete source code of this post can be cloned from github. Libraries Used Name Version Spring MVC 4.0 Spring Test 4.0 Junit 4.8.1 Servlet 3.0 Jackson Mapper 1.9.13 Json Path 0.8.1 Controller Code. Response/Request Model Object Controller […]
Continue reading…

 

How to mock dependencies using Mockito?

In today’s post I would share a sample program that mock dependencies of the unit under test using Mockito. Mockito is the most simple mocking framework I ever used for java. Mockito is annotation driven and the APIs perfectly written so that you don’t even have to open the API documents to understand it. The complete source […]
Continue reading…

 

How to mock a static method using JMockit?

Sometime static method is a necessary evil. Especially while you work with legacy codebases you will have to mock some static behaviors/methods out to get some code coverage going for your area of interest. Today, I will share a very simple example of static method/behavior mocking using JMockit. The complete source code of this article […]
Continue reading…

 

Separate unit and integration testcases using JUnit Category.

This post is about separating Unit and Integration testcases using JUnit category and running those separately using maven. This post in NOT about moving unit and integration testcases into separate test source folders. With the introduction of org.junit.experimental.categories.Category annotation in JUnit 4.x we are in a position to separate integration testcases using annotation. Basically Category […]
Continue reading…

 

Java Mutation Testing With PIT

In this post we will talk about setting up Pitest for mutation testing. Overview of mutation testing Standard test coverage tools like Clover or EclEmma just check if a given statement or branch is executed by testcases. Mutation testing make sure that the a statement or a branch is executed and verified. Mutation testing achieve […]
Continue reading…

 

How to mock a dependency using JMockit?

In today’s post I would talk about mocking dependencies using JMockit. To write clean and complete unit test cases we have to mock out the dependencies. The complete source code of this blog can be cloned from github Steps involved in mocking a dependency using JMockit Mock the dependency reference using @Injectable Create a NonStrictExpectations […]
Continue reading…

 

How to test private static methods using JMockit?

We all know to practice better test driven development we should avoid using static behaviors in java. However while you are dealing with legacy code bases you may have to test the static private behaviors/methods independently to make sure that code is working as expected. JMockit testing framework let you do that. The API for […]
Continue reading…

 

How to test private methods using JMockit?

When you are dealing with legacy code base that doesn’t have enough test coverage it would be sometime very necessary to test private methods/behaviors without going through the public methods/behavior. If your public method/behavior that invoke private method/behavior is too long and too complicated to cover with the limited time frame and you are only […]
Continue reading…