Blog Archives
1 2 3

01: JUnit with Mockito step by step

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

Step 2: Import into eclipse.

#1. Validator code & unit testing

Step 3: Validator interface & implementation

Step 4: Write a unit test to test the “ValidatorImpl.java”.

Read more ›



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” in the file system into eclipse. File –> Import –> “Existing Maven Projects” and then select the “simple-mocking-test”

Read more ›



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 Layer DAO Layer This layer will be mocked by Mockito in the next step. … Read more ›...

Members Only Content
Log In Register Home


04: Mockito partially mocking with @Spy

This extends Part 2: Mockito to fully mock the DAO layer by modifying the service layer to demonstrate partial mocking with “Mockito.spy”. In the “SimpleServiceImpl” we are interested in only testing the method “processUser(int id)” and want to mock the method “getUserById(int id)” by always returning “Sam”. So, … Read...

Members Only Content
Log In Register Home


05: Mockito & PowerMock partially mocking private methods with @Spy

This extends Part 3: Mockito partially mocking with @Spy by making the method “processUser(int id)” as a private method. Mockito framework cannot mock “private” methods, hence the “PowerMock” framework is added to the pom.xml file Step 1: Add “PowerMock” … Read more ›...

Members Only Content
Log In Register Home


06: Mockito & PowerMock for mocking static methods

This extends Part 4: Mockito & PowerMock for partially mocking private methods to mock “static” methods.

How to use both Spring JUnit and PowerMock runners?

By using the “@PowerMockRunnerDelegate” from the “powermock-module-junit4” jar.

So, need to use compatible “Mockito” and “PowerMock”.

Read more ›



5 Java unit testing interview Questions and Answers

Q1 Why use mock objects in unit testing? A1 Unit testing is widely accepted as a “best practice” for software development. When you write an object, you must also provide an automated test class containing methods by calling its various public methods with various parameters and making sure that the...

Members Only Content
Log In Register Home


1 2 3
Why & What are the benefits

🎯 Why java-success.com?

🎯 What are the benefits of Q&As approach?

Learn by categories such as FAQs – Core Java, Key Area – Low Latency, Core Java – Java 8, JEE – Microservices, Big Data – NoSQL, Architecture – Distributed, Big Data – Spark, etc. Some posts belong to multiple categories.

800+ Java & Big Data Q&As Menu

Top