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 — 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 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…

 

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…