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” folder that was created by the “Step 1” from the file system.

Step 3: Add the testing, mocking, and Spring libraries to the pom.xml.

Step 4: Service and DAO layer interfaces and implementations

Service Layer
DAO Layer

Step 5: Wiring the DI via Java config.

Step 6: The JUnit test class. This is more of a JUnit integration testing than unit testing as the test spans service and dao layers. In Part 2, I will be mocking the Dao layer with the Mockito framework

Step 7: Run as JUnit test.

Java Interview FAQs

800+ Java Interview Q&As