# JUnit

> A common tool for writing tests for Java code. It also runs them.

**Field:** Software Development  
**Category:** Testing & Quality  
**Also known as:** JUnit 6, JUnit 5, JUnit Jupiter

## Think of it like

Think of it like a checklist clipboard for Java code. Each line is a check, and it marks pass or fail.

## Definition

JUnit is a widely used framework for testing Java code. You write each test as a method and mark it with @Test. Inside, assert methods check the results. Build tools like Maven and Gradle run JUnit tests for you. The current version is JUnit 6, which needs Java 17 or newer.

## Example

Emma writes a JUnit test that checks a price of 100 becomes 120 with tax. Gradle runs it with every build.

## Example code

```java
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

class PriceTest {
    @Test
    void addsTax() {
        assertEquals(120, Price.withTax(100));
    }
}
```

One test method, marked @Test, with one check inside.

## Why it matters

Almost every Java project uses it. Most Java tools know how to run it.

## Common mistake

Mixing imports from old and new JUnit versions. Tests then quietly fail to run.

## Three principles

- **@Test methods.** Each test is a marked method.
- **Assertions.** assertEquals and friends check results.
- **Build tools run it.** Maven and Gradle know it.

## Related terms

- [Unit Test](https://learn.benibix.com/term/development/unit-test)
- [Assertion](https://learn.benibix.com/term/development/assertion)
- [Java](https://learn.benibix.com/term/development/java)
- [Test Runner](https://learn.benibix.com/term/development/test-runner)
- [pytest](https://learn.benibix.com/term/development/pytest)

![A table of test tools by job. Unit tests: Jest and Vitest for JavaScript, pytest for Python, JUnit for Java. UI components: Testing Library, which finds things the way a user does. Browser end-to-end tests, lit up: Cypress, Playwright and Selenium, which drive a real browser.](https://learn.benibix.com/diagrams/dev3-test-tools.svg)

---

Source: https://learn.benibix.com/term/development/junit
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
