Category Archives: JUnit

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 »

Customizing Display Names of Parameterized Tests in JUnit 5

By default, the displayName of a parameterized test invocation contains the invocation index and the String representation of all arguments for that specific invocation. However, you can customize invocation display names via the name attribute of the @ParameterizedTest annotation. Below are the placeholders are supported within custom display names. Placeholder Description {index} the current invocation… Read More »

Argument Aggregation in Parameterized Tests in Junit 5

This post talks about Argument Aggregation supports provided by JUnit Jupiter in the case of  @ParameterizedTest By default, each argument provided to a @ParameterizedTest method corresponds to a single method parameter. Consequently, argument sources that are expected to supply a large number of arguments can lead to large method signatures. In that case, an ArgumentsAccessor may… Read More »