Junit Test case sample

Step 1: Java code

package com.math;

public class AgnClass {
	public int Sum(int x, int y) {
		return x + y;

Step 2: Junit Test case for the above Java code

package com.math;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class AgnClassTest {

	public void testSum() {
		AgnClass nav = new AgnClass();
		assertEquals("Result", 15, nav.sum(10, 5));

Step 3: Right click on the AgnClassTest program and run as junit, then by means of green color indication we can understand the success of the test case and program.

398 total views, 1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *