Home » Tag Archives: Mockito

Tag Archives: Mockito

Writing Clean Tests – Trouble in Paradise

mockito-logo

If our code has obvious faults, we are very motivated to improve it. However, at some point we decide that our code is “good enough” and move on. Typically this happens when we think that the benefits of improving our existing code are smaller than the required work. Of course, if we underestimate our return of investment, we can make ...

Read More »

Book Review: Mockito Essentials

mockito-logo

The subtitle of Sujoy Acharya‘s Mockito Essentials (Packt Publishing, October 2014) is: “A practical guide to get you up and running with unit testing using Mockito.” The Preface and seven chapters in Mockito Essentials span approximately 190 substantive pages. Preface In the Preface, author Sujoy Acharya writes that Mockito Essentials “is an advanced-level guide that will help software developers to ...

Read More »

Unit Testing exercise with FizzBuzz and Mockito

mockito-logo

I sometimes use FizzBuzz to demonstrate the basics of unit testing to newbies. Although FizzBuzz is really simple problem, it can also be used to demonstrate more advanced unit testing techniques like mocking. The FizzBuzz Kata: “Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for ...

Read More »

Mockito 101

mockito-logo

Mockito is a mocking framework that lets you write beatiful tests with clean and simple API. It biases toward minimal specifications, makes different behaviors look different, and displays clear error messages. Creating Mocks To create a mock using Mockito, simply annotate mocks with @Mock and call MockitoAnnotations.initMocks(this).       import org.mockito.Mock; import org.mockito.MockitoAnnotations; public class FooClassTest { @Mock mockFoo; ...

Read More »

Writing Clean Tests – Divide and Conquer

junit-logo

A good unit test should fail for only one reason. This means that a proper unit test tests only one logical concept. If we want to write clean tests, we have to identify those logical concepts, and write only one test case per logical concept. This blog post describes how we can identify the logical concepts found from our tests, ...

Read More »

Writing Clean Tests – Beware of Magic

junit-logo

It is pretty hard to figure out a good definition for clean code because everyone of us has our own definition for the word clean. However, there is one definition which seems to be universal: Clean code is easy to read. This might come as a surprise to some of you, but I think that this definition applies to test ...

Read More »

What are Mockito Extra Interfaces?

mockito-logo

Mockito is my favored little helper if it comes down to write light weight JUnit tests. It is very useful to replace the ‘real’ dependencies of a unit under test easily by mocks if necessary. In particular when working on the borderline to framework APIs such dependencies can otherwise be very expensive to setup. But sometimes the situation is a ...

Read More »

Getting started with Mocking in Java using Mockito

mockito-logo

We all write unit tests but the challenge we face at times is that the unit under test might be dependent on other components. And configuring other components for unit testing is definitely an overkill. Instead we can make use of Mocks in place of the other components and continue with the unit testing. To show how one can use ...

Read More »

Mockito Templates for Eclipse

mockito-logo

Sometimes I miss the forest for the trees – and that for a disturbingly long time. I just became aware of this once again recently, typing one of the more verbose mockito expressions for the umpteenth time. The statement in question was a doAnswer(Answer) construct which always feels a bit cumbersome to code with the static import and generics stuff ...

Read More »

Mock final class

mockito-logo

Foreword If you already read some other blog post about unusual mocking, you can skip prelude via this link. I was asked to put together examples how to mock Java constructs well know for their testability issues:         Mock private method Mock final method Mock final class Mock constructor Mock static method I am calling these techniques ...

Read More »
Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close