What, why and how?

Why?

Why

  • The "Future"
  • Clear APIs for integration with tools, e.g. IDEs
    • JUnit 4 was a reflection hack fest!
  • Extensibility
  • New features

What?

JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage

And what was JUnit 4?

https://github.com/sormuras/junit5-there-is-no-junit5

No decoupling possible :(

https://github.com/sormuras/junit5-there-is-no-junit5

And JUnit 5?

https://github.com/sormuras/junit5-there-is-no-junit5

JUnit 5 Architecture

https://github.com/sormuras/junit5-there-is-no-junit5

Features Spotlight

  • @DisplayName
  • @Nested
  • @ParameterizedTest
    • @ValueSource
    • @EnumSource
    • @CsvSource
    • @MethodSource
    • @ArgumentSource
  • JUnit Pioneer

Getting Started (Maven)

<dependencies>
	<dependency>
		<groupId>org.junit.jupiter</groupId>
		<artifactId>junit-jupiter</artifactId>
		<version>${junit.jupiter.version}</version>
		<scope>test</scope>
	</dependency>
</dependencies>

Getting Started (First Test)

import static org.junit.jupiter.api.Assertions.assertEquals;

import example.util.Calculator;

import org.junit.jupiter.api.Test;

class MyFirstJUnitJupiterTests {

    private final Calculator calculator = new Calculator();

    @Test
    void addition() {
        assertEquals(2, calculator.add(1, 1));
    }

}

Trying it out with a Kata

JUnit 5 Intro

By Kevin Wittek

JUnit 5 Intro

  • 1,405