Blog Archives
1 2 3 4

01: JMockit interview Q&As & examples on @Injectable Vs @Mocked Vs @Capturing Vs @Tested

This extends 6 JUnit & JMockit interview questions & answers on Java Unit testing – Part 1. It is very essential to understand how these 3 annotations work in JMockit to write unit tests quickly &

Read more ›



01: JUnit with Mockito tutorial step by step

JUnit with Mockito tutorial step by step. Mockito is a popular mocking framework used along with JUnit. JMockit is more popular than Mockito.

Step 1: Create a simple maven project say “code-quality”

Read more ›



01: Mockito interview Q&As & examples on @Mock, @Spy, @Captor and @InjectMocks

Firstly, you need the pom.xml entry to bring in the Mockito library.

@InjectMocks

Firstly, annotate the Test class with @RunWith(MockitoJUnitRunner.class) as shown below. The @InjectMocks annotation creates an instance of the class and injects the mocks that are created with the @Mock (or @Spy) annotations into this instance.

Read more ›



02: JMockit interview Q&As & examples on Expectations & Verifications

This extends 01: JMockit interview Q&As on @Injectable Vs @Mocked Vs @Tested. The purpose of mocking objects is to return an expected value to test the logic of the class under test.

Read more ›



02: Mockito interview Q&As & examples on @Spy

A spy in mockito is a partial mock where part of the object will be mocked and part will use real method invocations. You can create a Spy a number...



02: Unit testing with JUnit, Mockito & Spring

Step 1: Create a simple Maven project from a command-line. Just press enter for all the prompts.

Step 2: Import the above “simple-mocking-test”

Read more ›



03: JMockit interview Q&As & examples on initialising @Injectable fields

This extends 02: JMockit interview Q&As & examples on Expectations & Verifications. We have already discussed that a non-final instance field annotated as @Tested in the test class will be...



03: Mockito interview Q&As & examples on @Mock, Mockito.mock(…) and @MockBean

Unlike a @Spy where you are spying on a real object, when you mock, you are creating a complete mock or fake object. Q: What are the different ways to...



03: Mockito to fully mock the DAO layer

This extends Part 1: Unit testing with JUnit, Mockito & Spring by mocking the DAO layer with the Mockito framework. Step 1: Service and DAO layer interfaces and implementations Service...



04: JMockit interview Q&As & examples on @Injectable vs @Mocked

This extends 01: JMockit interview Q&As on @Injectable Vs @Mocked Vs @Tested. The purpose of mocking objects is to return an expected value to test the logic of the class...



1 2 3 4
Answers are detailed to be useful beyond job interviews. A few Q&As each day will make a huge difference in 3 to 24 months to go places depending on your experience.
Top