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…

 

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…

 

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…

 

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…