RKTechGame | Introduction to JUnit

JUnit kya hai?

JUnit ek open-source testing framework hai jo Java programs ke liye unit testing support karta hai. Iska use test-driven development (TDD) me hota hai jisme code likhne se pehle tests likhe jate hain.

JUnit ke Fayde

Basic JUnit Test Structure

JUnit me test likhne ke liye ek class create karte hain jisme test methods ko @Test annotation diya jata hai:

import org.junit.Test;
import static org.junit.Assert.*;

public class CalculatorTest {
   @Test
   public void testAdd() {
       Calculator calc = new Calculator();
       int result = calc.add(5, 3);
       assertEquals(8, result);
   }
}

Is example me testAdd method Calculator class ke add method ko test kar raha hai.

JUnit Annotations ke Types