Home » Tag Archives: Mockito (page 2)

Tag Archives: Mockito

Use Mockito to mock autowired fields

mockito-logo

Dependency injection is very powerful feature of Inversion of Control containers like Spring and EJB. It is always good idea to encapsulate injected values into private fields. But encapsulation of autowired fields decreases testability. I like the way how Mockito solved this problem  to mock autowired fields. Will explain it on example. (This blog post expects that you are little ...

Read More »

Testing Spring components with Mockito

mockito-logo

Be able to unit test your spring components without the need of loading the full spring-context with its ad-hoc test configurations it is ,in my opinion, a great advantage because it’s clean, easy to maintain, faster to write, smooth to alter. A way to achieve this goal is to use Mockito and tell him to replace the @Autowired components in ...

Read More »

Imbibing the Fluency of Mockito

mockito-logo

I recently found myself writing some code to integrate two disparate platforms. One of these systems is Java based and the other, while not written in Java, offers a Java API. I’ll call these systems Foo and Bar, respectively. It became obvious before I had written a line of code, however, that testing the eventual adapter would require I explicitly ...

Read More »

Mockito – RETURNS_DEEP_STUBS for JAXB

mockito-logo

Sorry for not having written for some time but I was busy with writing the JBoss Drools Refcard for DZone and I am in the middle of writing a book about Mockito so I don’t have too much time left for blogging… Anyway quite recently on my current project I had an interesting situation regarding unit testing with Mockito and ...

Read More »

JUnit and Mockito cooperation

mockito-logo

This time I want to make an overview of testing framework Mockito. Definitely this is one of the most popular tools for the testing of java code. I have already made the overview of the Mockito’s competitor – EasyMock. This post will be based on the sample application from the post about EasyMock. I mean classes which represent coffee machine ...

Read More »

Answering with Mockito

mockito-logo

When you are writing unit tests, you must keep in mind to not have dependencies to external components. To avoid this we use mock frameworks which for me the easiest one to use is Mockito. In this post we are going to see an ‘advanced’ technique used in Mockito to return same argument instance on a mocked method using Answer ...

Read More »

Test-driving Builders with Mockito and Hamcrest

mockito-logo

A lot of people asked me in the past if I test getters and setters (properties, attributes, etc). They also asked me if I test my builders. The answer, in my case is it depends. When working with legacy code, I wouldn’t bother to test data structures, that means, objects with just getters and setters, maps, lists, etc. One of ...

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