How to use JUnit to unit test code
In this blog post, I will be explaining how you can run JUnit unit tests to test your code. What is JUnit? JUnit is a unit testing framework for Java. It is used by developers to test individual code and ensure that code works the way it was intended to. The current version of JUnit is JUnit 5 . Why JUnit? Consider the following code snippet: package demo;public class MathDemo {public int add(int a,int b){return a+b;}public int subtract(int a,int b){return a-b;}} So this class has two methods, called add and subtract . The add method adds 2 numbers and returns the sum while the subtract methods returns the difference of the 2 input numbers. Now traditionally, if you want to test if this code works, you would write a main method like this: public static void main(String args[]){MathDemo mathDemo = new MathDemo();int sum = mathDemo.add(5,4);int diff = mathDemo.subtract(9, 3);System.out.println("Sum is "+sum);System.out.println("Difference is "+diff);...