Skip to content

About

code samples demonstrating fundamental concepts of the JUnit 6 testing framework.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

JUnit 6 Basics

A compact, beginner-friendly set of examples demonstrating fundamental unit-testing concepts with JUnit 6 (Jupiter) for Java projects.

Table of contents

Quick start

Requirements:

  • A JDK compatible with the project's Maven configuration (use the wrapper included below if unsure)
  • Maven (or use the provided Maven wrapper)

Run the test suite:

# On Unix / macOS
./mvnw test

# Or with a locally installed Maven
mvn test

What you'll find here

This repository contains short, focused test classes showing how to:

  • Write simple unit tests using JUnit 6 annotations and assertions
  • Organize test classes under a standard Maven layout
  • Use lifecycle callbacks to set up and tear down test state

Rather than duplicating code snippets in this README, each concept is demonstrated by an actual runnable test class in the repo — see Where the code lives.

How to run the examples

  1. Clone the repo:
git clone https://github.com/Ayshasharaf/java-testing-junit6.git
cd java-testing-junit6
  1. Run all tests:
./mvnw test
  1. Run a single test class or method from your IDE (IntelliJ, Eclipse) using the run icon next to the test or class.

Key concepts & common annotations

  • System Under Test (SUT): the class being tested
  • Test class: a Java class that contains one or more test methods annotated with @Test
  • Assertion: checks the actual result against the expected result
  • Test runner: executes tests and reports results

Common JUnit 6 (Jupiter) annotations:

  • @Test — mark a method as a test
  • @DisplayName("…") — provide a human-friendly name for a test or class
  • @Disabled — skip a test
  • @BeforeEach — run before every test method
  • @AfterEach — run after every test method
  • @BeforeAll — run once before all tests in the class (static)
  • @AfterAll — run once after all tests in the class (static)

Assertions covered

Each of the following is demonstrated in its own test class under src/test/java/com/learn/junit6/ (see below), using org.junit.jupiter.api.Assertions:

  • assertEquals
  • assertNotEquals
  • assertTrue
  • assertFalse
  • assertArrayEquals
  • assertThrows
  • assertNull
  • assertNotNull

Full API reference: JUnit 5/6 Assertions Javadoc

Where the code lives

  • src/test/java/com/learn/junit6/ — example test classes demonstrating the concepts and assertions above
  • pom.xml — Maven project file (dependency management, build settings)
  • mvnw, mvnw.cmd — Maven wrapper to run builds without a local Maven install

Open src/test/java/com/learn/junit6/ in your IDE to explore each example directly.

Contributing

  • Suggestions, corrections, and example additions are welcome.
  • If you add examples, prefer small focused tests that show one concept at a time.
  • Submit changes via pull request; include a short description and a test that demonstrates the change where appropriate.

License

MIT

References

About

code samples demonstrating fundamental concepts of the JUnit 6 testing framework.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages