SlideShare a Scribd company logo
JUnit5 –
The Next Generation of JUnit
Richard Langlois P. Eng.
Solutions Architect
10 août 2016
 Why JUnit5
 What is New
 Demo
 Migration Tips
10 août 2016
Agenda
 Junit 4 is an All-in-one library
 Difficult for IDEs to deal with the library.
10 août 2016
Why Junit 5
 Revamped codebase with a modular architecture.
 JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage
 Junit Platform: Defines TestEngine API for developing a testing framework that
runs on the platform.
 Junit Jupiter: provides TestEngine for running Junit 5 based tests on the
platform.
 Junit Vintage: provides TestEngine for running Junit 3 and Junit 4 based tests on
the platform.
 Test code depends only on the JUnit 5 API.
 IDE support: As of August 2016, supported by IntelliJ IDEA 2016.2
 Milestone 2 released on July 23, 2016
 GA release (due late 2016).
 Code samples available on GitHub (https://github.com/junit-team/junit5-samples)
10 août 2016
What is Junit 5
MODIFIEZ LE STYLE DU TITRE
Architecture
‱ Test code depends only on the
JUnit 5 API.
‱ IDEs and build tools depend on
the Launcher and Engine APIs
and can execute tests
independent of the testing
framework in use.
10 août 2016
 JUnit 4
Import org.junit.Test
public class JUnit4Test {
@Test
public void aJunit4TestCase() {
assertTrue(“message”, 5 > 6);
}
}
 JUnit 5
Import org.junit.jupiter.api.Test
class JUnit5Test {
@Test
void aJunit5TestCase() {
assertTrue(5 > 6, “message”);
}
}
10 août 2016
JUnit 4 vs JUnit 5
 New set of annotations which resides in a different package
(org.junit.jupiter.api) than their JUnit 4 counterparts:
 @Test: the method is a test
 @TestFactory: the method is a test factory for dynamic tests
 @DisplayName: declares a custom display name (class or method)
 @BeforeEach: method executed before each test method
 @AfterEach: method executed after each test method
 @BeforeAll: method executed before all test methods
 @AfterAll: method executed after all test methods
 @Nested: denotes that the class is a nested, non-static test class
 @Tag: declare a tag for filtering tests (class or method)
 @Disabled: disable a test class or test method
 @ExtendWith: register custom extensions
10 août 2016
What is New
 New package org.junit.jupiter.api
 Tests do not need to be public
 Meta-Annotation: Allows to define our own composed
annotation
 Display Names with @DisplayName(“
”)
 Can contain spaces, special chars, and emoji đŸ˜±
 Assertions
 Optional message is now the last parameter
 Grouped assertions using assertAll()
 expectThrows: check that method throws an exception,
and returns the exception object to allow further testing.
10 août 2016
What is New (continued)
 Assumptions: Skip the test execution if the assumption
condition is not met.
 E.g. assumeTrue, assumingThat
 Disabling test with @Disabled
 Tagging: used to enable/disable tests with specific tags
in a build and execution
 Equivalent of the Categories in JUnit 4
 e.g. @Tag(“fast”).
 Nested Tests: Allow expressing relationship among
several group of tests.
10 août 2016
What is New (continued)
 Extension Model:
 New extension API that supersedes the
previous @RunWith and @Rule extension mechanism
 Test constructors and methods are now permitted to have
parameters enabling dependency injection.
 2 built-in resolvers:
 TestInfo: information about the current test (e.g. display name)
 TestReporter: to publish additional data about the current test
run
 Custom ParameterResolver: Specified with
@ExtendWith
10 août 2016
What is New (continued)
 Dynamic tests:
 A DynamicTest is a test case generated at runtime.
 Generated at runtime by a factory method (annotated with
@TestFactory).
 @TestFactory method returns a Stream, Collection,
Iterable or Iterator of DynamicTest instances.
10 août 2016
What is New (continued)
1. AnnotationTestDemo.java
2. MetaAnnotationDemo.java
3. BeforeAfterDemo.java
4. DisplayNameDemo.java
5. AssertionsDemo.java
6. AssumptionsDemo.java
7. DisabledClassDemo.java
8. DisabledTestDemo.java
9. TaggingDemo.java
10. NestedTestDemo.java
11. ParameterTestInfoDemo.java
12. ParameterTestReporterDemo.java
13. DynamicTestDemo.java
10 août 2016
Demo
 Annotations reside in the org.junit.jupiter.api package.
 Assertions reside in org.junit.jupiter.api.Assertions.
 Assumptions reside in org.junit.jupiter.api.Assumptions.
 @Before and @After no longer exist; use @BeforeEach and
@AfterEach instead.
 @BeforeClass and @AfterClass no longer exist; use @BeforeAll and
@AfterAll instead.
 @Ignore no longer exists: use @Disabled instead.
 @Category no longer exists; use @Tag instead.
 @RunWith no longer exists; superseded by @ExtendWith.
 @Rule and @ClassRule no longer exist; superseded by @ExtendWith.
10 août 2016
JUnit 4 to JUnit 5 Migration Tips
 Project Homepage
 http://junit.org/junit5
 User Guide
 http://junit.org/junit5/docs/current/user-guide
 Javadoc
 https://junit.ci.cloudbees.com/job/JUnit5/javadoc
 GitHub
 https://github.com/junit-team/junit5
 Sample Projects
 https://github.com/junit-team/junit5-samples
 Twitter
 https://twitter.com/JUnitTeam
 Stack Overflow
 http://stackoverflow.com/tags/junit5
10 août 2016
References
 Questions?
 Next Lunch & Learn:
 Introduction to Docker, by John Okrasa
10 août 2016
Thank You !

More Related Content

PDF
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
PDF
JUnit 5
PDF
JUnit 5 - The Next Generation
PDF
Test code that will not slow you down
PPTX
TDD - Unit Testing
PPTX
Renaissance of JUnit - Introduction to JUnit 5
PPT
PPT
Google C++ Testing Framework in Visual Studio 2008
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
JUnit 5
JUnit 5 - The Next Generation
Test code that will not slow you down
TDD - Unit Testing
Renaissance of JUnit - Introduction to JUnit 5
Google C++ Testing Framework in Visual Studio 2008

What's hot (20)

PDF
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
PPT
Google mock for dummies
PPTX
Junit4&testng presentation
PDF
JUnit5 Custom TestEngines intro - version 2020-06
PDF
C++ Unit Test with Google Testing Framework
ODP
Test ng
PPTX
TestNG with selenium
PPTX
TestNG Session presented in Xebia XKE
PPT
Unit Testing RPG with JUnit
PPT
RPG Program for Unit Testing RPG
PDF
Agile mobile
PPT
Presentation_C++UnitTest
PPT
20111018 boost and gtest
PDF
Modern Python Testing
PPTX
Introduction to JUnit testing in OpenDaylight
PPTX
Selenium with java
PDF
ikp321-04
PDF
Quality of life through Unit Testing
PDF
TestNg_Overview_Config
ODP
Automated testing in Python and beyond
 
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
Google mock for dummies
Junit4&testng presentation
JUnit5 Custom TestEngines intro - version 2020-06
C++ Unit Test with Google Testing Framework
Test ng
TestNG with selenium
TestNG Session presented in Xebia XKE
Unit Testing RPG with JUnit
RPG Program for Unit Testing RPG
Agile mobile
Presentation_C++UnitTest
20111018 boost and gtest
Modern Python Testing
Introduction to JUnit testing in OpenDaylight
Selenium with java
ikp321-04
Quality of life through Unit Testing
TestNg_Overview_Config
Automated testing in Python and beyond
 
Ad

Similar to What is new in JUnit5 (20)

PDF
JUnit 5 — New Opportunities for Testing on the JVM
PDF
JUnit 5 - New Opportunities for Testing on the JVM
PPTX
JUnit 5 - from Lambda to Alpha and beyond
PPTX
Junit5 brujug
PPTX
JUnit 5: What's New and What's Coming - Spring I/O 2019
PDF
Testing with JUnit 5 and Spring - Spring I/O 2022
PDF
Testing with JUnit 5 and Spring
PDF
JUnit 5 Alpha
PDF
PPTX
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
PPT
3 j unit
PPTX
Session 4 -Junit- Testing Exceptions, Junit hooks.pptx
PPTX
JUnit- A Unit Testing Framework
PPTX
JUnit 5 Slides: Next generation Framework for Testing
PPTX
unit 1 (1).pptx
PPTX
Testing with Junit4
PDF
junit-160729073220 eclipse software testing.pdf
PPSX
Junit
PPTX
Testing Spring Boot application in post-JUnit 4 world
PDF
Unit testing with Junit
JUnit 5 — New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - from Lambda to Alpha and beyond
Junit5 brujug
JUnit 5: What's New and What's Coming - Spring I/O 2019
Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring
JUnit 5 Alpha
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
3 j unit
Session 4 -Junit- Testing Exceptions, Junit hooks.pptx
JUnit- A Unit Testing Framework
JUnit 5 Slides: Next generation Framework for Testing
unit 1 (1).pptx
Testing with Junit4
junit-160729073220 eclipse software testing.pdf
Junit
Testing Spring Boot application in post-JUnit 4 world
Unit testing with Junit
Ad

More from Richard Langlois P. Eng. (7)

PDF
Monitoring with Prometheus
PDF
Continuous Test Automation, by Richard Langlois P. Eng. and Yuri Pechenko.
PDF
Microservice Architecture Patterns, by Richard Langlois P. Eng.
PDF
Reactive Programming in Java and Spring Framework 5
PPTX
What's New in Java 9
PPTX
DevOps, Yet Another IT Revolution
PDF
Introduction to Reactive Microservices Architecture.
Monitoring with Prometheus
Continuous Test Automation, by Richard Langlois P. Eng. and Yuri Pechenko.
Microservice Architecture Patterns, by Richard Langlois P. Eng.
Reactive Programming in Java and Spring Framework 5
What's New in Java 9
DevOps, Yet Another IT Revolution
Introduction to Reactive Microservices Architecture.

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
ai tools demonstartion for schools and inter college
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Nekopoi APK 2025 free lastest update
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
AI in Product Development-omnex systems
PPTX
Introduction to Artificial Intelligence
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPT
Introduction Database Management System for Course Database
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Internet Downloader Manager (IDM) Crack 6.42 Build 41
2025 Textile ERP Trends: SAP, Odoo & Oracle
ai tools demonstartion for schools and inter college
Understanding Forklifts - TECH EHS Solution
CHAPTER 2 - PM Management and IT Context
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
Wondershare Filmora 15 Crack With Activation Key [2025
How Creative Agencies Leverage Project Management Software.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Nekopoi APK 2025 free lastest update
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
AI in Product Development-omnex systems
Introduction to Artificial Intelligence
Odoo POS Development Services by CandidRoot Solutions
ISO 45001 Occupational Health and Safety Management System
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Introduction Database Management System for Course Database
Odoo Companies in India – Driving Business Transformation.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design

What is new in JUnit5

  • 1. JUnit5 – The Next Generation of JUnit Richard Langlois P. Eng. Solutions Architect 10 aoĂ»t 2016
  • 2.  Why JUnit5  What is New  Demo  Migration Tips 10 aoĂ»t 2016 Agenda
  • 3.  Junit 4 is an All-in-one library  Difficult for IDEs to deal with the library. 10 aoĂ»t 2016 Why Junit 5
  • 4.  Revamped codebase with a modular architecture.  JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage  Junit Platform: Defines TestEngine API for developing a testing framework that runs on the platform.  Junit Jupiter: provides TestEngine for running Junit 5 based tests on the platform.  Junit Vintage: provides TestEngine for running Junit 3 and Junit 4 based tests on the platform.  Test code depends only on the JUnit 5 API.  IDE support: As of August 2016, supported by IntelliJ IDEA 2016.2  Milestone 2 released on July 23, 2016  GA release (due late 2016).  Code samples available on GitHub (https://github.com/junit-team/junit5-samples) 10 aoĂ»t 2016 What is Junit 5
  • 5. MODIFIEZ LE STYLE DU TITRE Architecture ‱ Test code depends only on the JUnit 5 API. ‱ IDEs and build tools depend on the Launcher and Engine APIs and can execute tests independent of the testing framework in use. 10 aoĂ»t 2016
  • 6.  JUnit 4 Import org.junit.Test public class JUnit4Test { @Test public void aJunit4TestCase() { assertTrue(“message”, 5 > 6); } }  JUnit 5 Import org.junit.jupiter.api.Test class JUnit5Test { @Test void aJunit5TestCase() { assertTrue(5 > 6, “message”); } } 10 aoĂ»t 2016 JUnit 4 vs JUnit 5
  • 7.  New set of annotations which resides in a different package (org.junit.jupiter.api) than their JUnit 4 counterparts:  @Test: the method is a test  @TestFactory: the method is a test factory for dynamic tests  @DisplayName: declares a custom display name (class or method)  @BeforeEach: method executed before each test method  @AfterEach: method executed after each test method  @BeforeAll: method executed before all test methods  @AfterAll: method executed after all test methods  @Nested: denotes that the class is a nested, non-static test class  @Tag: declare a tag for filtering tests (class or method)  @Disabled: disable a test class or test method  @ExtendWith: register custom extensions 10 aoĂ»t 2016 What is New
  • 8.  New package org.junit.jupiter.api  Tests do not need to be public  Meta-Annotation: Allows to define our own composed annotation  Display Names with @DisplayName(“
”)  Can contain spaces, special chars, and emoji đŸ˜±  Assertions  Optional message is now the last parameter  Grouped assertions using assertAll()  expectThrows: check that method throws an exception, and returns the exception object to allow further testing. 10 aoĂ»t 2016 What is New (continued)
  • 9.  Assumptions: Skip the test execution if the assumption condition is not met.  E.g. assumeTrue, assumingThat  Disabling test with @Disabled  Tagging: used to enable/disable tests with specific tags in a build and execution  Equivalent of the Categories in JUnit 4  e.g. @Tag(“fast”).  Nested Tests: Allow expressing relationship among several group of tests. 10 aoĂ»t 2016 What is New (continued)
  • 10.  Extension Model:  New extension API that supersedes the previous @RunWith and @Rule extension mechanism  Test constructors and methods are now permitted to have parameters enabling dependency injection.  2 built-in resolvers:  TestInfo: information about the current test (e.g. display name)  TestReporter: to publish additional data about the current test run  Custom ParameterResolver: Specified with @ExtendWith 10 aoĂ»t 2016 What is New (continued)
  • 11.  Dynamic tests:  A DynamicTest is a test case generated at runtime.  Generated at runtime by a factory method (annotated with @TestFactory).  @TestFactory method returns a Stream, Collection, Iterable or Iterator of DynamicTest instances. 10 aoĂ»t 2016 What is New (continued)
  • 12. 1. AnnotationTestDemo.java 2. MetaAnnotationDemo.java 3. BeforeAfterDemo.java 4. DisplayNameDemo.java 5. AssertionsDemo.java 6. AssumptionsDemo.java 7. DisabledClassDemo.java 8. DisabledTestDemo.java 9. TaggingDemo.java 10. NestedTestDemo.java 11. ParameterTestInfoDemo.java 12. ParameterTestReporterDemo.java 13. DynamicTestDemo.java 10 aoĂ»t 2016 Demo
  • 13.  Annotations reside in the org.junit.jupiter.api package.  Assertions reside in org.junit.jupiter.api.Assertions.  Assumptions reside in org.junit.jupiter.api.Assumptions.  @Before and @After no longer exist; use @BeforeEach and @AfterEach instead.  @BeforeClass and @AfterClass no longer exist; use @BeforeAll and @AfterAll instead.  @Ignore no longer exists: use @Disabled instead.  @Category no longer exists; use @Tag instead.  @RunWith no longer exists; superseded by @ExtendWith.  @Rule and @ClassRule no longer exist; superseded by @ExtendWith. 10 aoĂ»t 2016 JUnit 4 to JUnit 5 Migration Tips
  • 14.  Project Homepage  http://junit.org/junit5  User Guide  http://junit.org/junit5/docs/current/user-guide  Javadoc  https://junit.ci.cloudbees.com/job/JUnit5/javadoc  GitHub  https://github.com/junit-team/junit5  Sample Projects  https://github.com/junit-team/junit5-samples  Twitter  https://twitter.com/JUnitTeam  Stack Overflow  http://stackoverflow.com/tags/junit5 10 aoĂ»t 2016 References
  • 15.  Questions?  Next Lunch & Learn:  Introduction to Docker, by John Okrasa 10 aoĂ»t 2016 Thank You !