JUnit5 Introduction

What is Unit Testing?

Unit Testing is defined as a type of software testing where individual components of a software tested.

Unit Testing of a software product is carried out during the development of an application. And an individual component may be either an individual function or a procedure. Unit Testing is typically done by the developer.

For example:

A method of adding two number: You create a method named addition(). After creating this addition(), you will do unit testing that the code written in addition() method for adding two numbers working fine or not.

So to do testing, developer will need to make different cases in which a sets of two numbers will be passed as input to addition() method and checked if the desired result is coming or not.

Case 1: If you pass as input (2, 3). It should add 2 and 3 and return 5 as a result.

Case 2: If you pass as input (10,20). It should add 10 and 20 and return 30 as a result.

Case 3: If you pass as input (-2,-5). It should add -2 and -5 and return -7 as a result.

What is the importance of Unit Testing?

  1. To verify the correctness of code.
  2. To test every function and procedure.
  3. To fix bug early in development cycle.
  4. To save testing cost.
  5. Understand the code base and enable developer to make changes quickly.

What is JUnit5?

JUnit5 is the next generation of JUnit. It facilitates to do unit testing smoothly as it enable many different styles of testing.

It allows you to use static import for its asset Statements. So that test code remains short and easy to read.

JUnit5 allows multiple instance of runners to work simultaneously.

JUnit5 consists feature like lambda functions, makes test more powerful and easier to maintain.