Category Archives: JUnit

Mockito and JUnit Integration Using Maven Example

In this post, We will learn How to integrate  Mockito  3 and JUnit  5 using a demo project Mockito Extension Mockito provides an implementation for JUnit5 or Jupiter extensions in the library – mockito-junit-jupiter. we have to include the following dependency with test scope  in our pom.xml

Let’s try to understand the above concept using a demo project… Read More »

How to mock interface using Mockito example

In this post, We will learn How to set up Mockito Maven Dependency Workspace in Eclipse? We can use org.mockito.Mockito class mock() method to create a mock object of a given class or interface. This is really the simplest way to mock an object. We can mock an object using @Mock annotation also. It’s really useful… Read More »

What are the Benefits of Mockito ?

Below are the main advantages or benefits of Mockito: Annotation Support: It supports creating mocks using various annotations. No Handwriting: We do not need to write mock objects by own. Return value support: Supports return values. Exception support: It supports exceptions. Order check support: It also supports check on the order of method calls. Refactoring Safe: Even if we… Read More »

Why Need for mocking ?

Before using the Mocking technique, Let’s try to understand the reasons for using mocking. Why Need for mocking (Reason-01)? If you want to test a component that depends on the other component, but that component is under development. It generally happens when working in a team and different components are divided between several team members.… Read More »

What is Mocking and Mockito?

   What is Mocking?  Mocking is a way to test the functionality of a class in an isolation fashion. When we use mockito then we do not require a database connection or file server read or properties file to read to test functionality. The mocking object usually does the mocking of the real service. A… Read More »

JUnit 5 Temporary Directory Support

The built-in TempDirectory extension is mainly used to create and cleanup a temporary directory for an individual test or all tests in a test class. To use it, We have to annotate a non-private field of type java.io.File Or java.nio.file.Path with @TempDir or add a parameter of type  java.io.File Or java.nio.file.Path annotated with @TempDir to a lifecycle method or test… Read More »

JUnit 5 vs JUnit 4

JUnit 5 aims to adapt the java 8 styles of coding and to be more robust and flexible than JUnit 4. JUnit 5 vs JUnit 4 – Annotations FEATURE JUnit 4 JUnit 5 Declare a test method @Test @Test The annotated method executes before all test methods in the current class @BeforeClass @BeforeAll The annotated… Read More »

How to execute Junit 5 tests in eclipse IDE

To execute Junit 5 tests in eclipse, we need to add the following dependencies in with test scope in pom.xml 1.junit-platform-runner : provides the location of the JUnitPlatform runner 2.junit-jupiter-api :API for writing tests, including @Test, etc. It is transitively included when we include JUnit-Jupiter-engine. 3.junit–jupiter-engine :It is the implementation of the TestEngine API for… Read More »

JUnit 5 Test Templates for Eclipse

Eclipse has really great tooling support for JUnit test cases. Using code templates for JUnit test cases configured in Eclipse has a great addition to faster test development.  Let’s learn how to create and import JUnit 5 test templates in eclipse. JUnit 5 Test Templates Given below template will help us to configure three JUnit 5 template methods… Read More »

JUnit 5 Test Suites Examples

We can use JUnit 5 test suites to run tests spread into multiple test classes and different packages.  JUnit 5 provides out of box two annotations: @SelectPackages and @SelectClasses to create test suites. Additionally, we may use other annotations for filtering test packages, classes, or even test methods. Create Test Suite with @SelectPackages We can… Read More »