JUnit

Java Unit Testing Framework

Introduction

JUnit is the most popular unit testing framework for Java, used to write repeatable test code. New projects should use JUnit 5, and existing JUnit 4 projects can migrate using JUnit Vintage.

Contents

Version Selection

  • JUnit 5: Preferred for new projects, rich modern features
  • JUnit 4: For legacy project maintenance
  • JUnit Vintage: For backward compatibility running older tests

Quick Start

Maven

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>5.14.3</version>
    <scope>test</scope>
</dependency>

Gradle

testImplementation 'org.junit.jupiter:junit-jupiter:5.14.3'