Tags » Mockito

Mockito - Partial Mocks - mock() and spy()

Mockito.mock

Ok so say I have two methods in my class –

public class ToBeMocked {

    public String methodOne() {
        return "methodOne calls methodTwo - " + this.methodTwo();
    }
    	   
    public String methodTwo() {   
        return "Hi Im methodTwo";
    }

}
… 244 more words
Mockito

Powermock - How to mock static, private methods (Powermock tutorial)

This tutorial tries to explain how to use Powermock to mock static and private methods.

Powermock is an awesome framework that extends mock frameworks like… 688 more words

Java

Book review: Sujoy Acharya - Mockito essentials

A few weeks back I was contacted by Packt Publishing to review a relatively newly published book: Mockito essentials. Without any further talk, let’s see: 652 more words

JUnit

Using Matches for null parameter with Mockito

I was using Mockito to write a unit test today and had a brief struggle trying to write a Matcher for a parameter I expected to be null. 156 more words

Java

Mockito and Power Mockito - Cheatsheet

@RunWith(PowerMockRunner.class) – Tell Junit that run this test using PowerMockRunner

@PrepareForTest(A.class) – This is needed when we need to test static methods of A class… 585 more words

Java

Some thoughts on JUnit Test with Mockito Part II

So in the previous post we talked about some resources and concepts we should understand before writing JUnit tests with Mockito.

Well, based on my recent experience, they may not be enough, especially when our code has many dependencies or collaborators and we have to mock all of them to do the test. 418 more words

Java

Dynamically Mocking Response Based On Parameters In Unit Tests

This post we will mock a method based on parameters passed to method at runtime with a realtime example.

lets say for example, I have a list of user email ids, then i am calling a service to find out list of subscribed and unsubscribed users, so the response from the service will contain two lists, List<String> subscribed and List<String> unsubscribed.

510 more words
Java