How to avoid call to super class constructors/methods using JMockit?

When you work with legacy codebase, sometime you would like to avoid the call to super constructor and super methods so that you can focus on covering sub class. package com.ourownjava.tdd.jmockit; /** * * @author Sanju Thomas * */ public class BaseClass { public BaseClass(final String name){ throw new IllegalArgumentException(name); } } package com.ourownjava.tdd.jmockit; /** […]
Continue reading…

 

How to execute junit test cases parallely using maven surefire plugin?

Junit test parallel execution can bring down the test execution time considerably. The only condition is that your test cases must be independent. The state shall not be shared across test cases. Today, I shall share a maven project with parallel test execution configured using maven surefire plugin. The complete source code can be found […]
Continue reading…

 

JMockit – Initializing the class under test and dependencies using @Tested annotation

In today post, I would give you a simple example to demonstrate the use of @Tested annotation and use of invocation count in the expectation block to avoid explicit verification. @Tested annotation would initialize the field of the class under test and wire the dependencies by type. In the example given below, the fileService field […]
Continue reading…

 

JMockit – Verify arguments passed to mocks using withCapture

While you test using mocks it would be necessary sometime to capture the arguments passed into mocked behavior. JMockit Verification.withCapture method can be used to capture the argument passed into a mocked behavior. The complete source code for this article can be found in the github   package com.ourownjava.tdd.mockit; import javax.naming.AuthenticationException; /** * * @author […]
Continue reading…

 

Mockito – Verify arguments passed to mocks using ArgumentCaptor

In certain scenarios like if we have no control or handle of argument passed into a mock we can use Mockito ArgumentCaptor to verify if certain arguments where passed to mocks. The complete source code used in this article can be cloned from github package com.ourownjava.tdd.mockito.capture; /** * * @author Sanju Thomas * */ public […]
Continue reading…

 

Mocking exception using JMockit

In today’s post I would talk about mocking exceptions using JMockit. You would like to test exception scenarios, especially when you deal with third party services. This will help you to fine tune your code to deal with the exception. During the development time testing an exception scenario without the help of the second party/third […]
Continue reading…

 

Vending Machine Kata – Java

Recently one of the companies asked me to solve Vending Machine Kata given here (https://github.com/guyroyse/vending-machine-kata) as their first level of screening. Though I couldn’t solve it completely in less than three hours I have covered most of the usecases. You can find my solution here. (https://github.com/sanjuthomas/vending-machine) You will have to add logic to complete the […]
Continue reading…