SlideShare a Scribd company logo
1 of 42
from Lambda to Alpha and Beyond ā€¦
Sam Brannen
@sam_brannen
JUnit
2
Sam Brannen
ā€¢ Spring and Java Consultant @
ā€¢ Java Developer for over 17 years
ā€¢ Spring Framework Core Committer since 2007
ā€¢ Swiss Spring User Group Lead
ā€¢ Trainer & Conference Speaker
ā€¢ JUnit 5 Core Committer since October 2015
3
Swiftmind
Experts in Spring and Enterprise Java
Areas of expertise
ā€¢ Spring *
ā€¢ Java EE
ā€¢ Software Architecture
ā€¢ Software Development
Where you find us
ā€¢ Zurich, Switzerland
ā€¢ @swiftmind
ā€¢ http://www.swiftmind.com
4
A Show of Handsā€¦
5
Agenda
ā€¢ Impetus for Change
ā€¢ JUnit Lambda
ā€¢ Roadmap
ā€¢ JUnit 5
ā€¢ Feedback
ā€¢ Q&A
6
Impetus for Change
7
Why a New Version of JUnit?
ā€¢ JUnit 4.0 was released a decade ago
ā€“ a lot has changed since thenā€¦
ā€“ testing needs have matured
ā€“ expectations have grown
ā€¢ Modularity ļƒ  big ball of mud
ā€¢ Test discovery and execution ļƒ  tightly coupled
ā€¢ Extensibility ļƒ  lot of room for improvement
ā€¢ Letā€™s not forget Java 8
8
Modularity in JUnit 4
ā€¢ Sure there are packages
ā€“ butā€¦ thereā€™s only THE junit.jar
9
JUnit 4 Runner API
ā€¢ Very powerful
ā€¢ In fact, it can do anything
ā€¢ Butā€¦ you canā€™t combine Runners
ā€¢ Parameterized + SpringJUnit4ClassRunner ļƒ  no way
10
JUnit 4ā€¦ Rulesā€¦ are meant to be broken
ā€¢ JUnit 4.7: MethodRule (@Rule)
ā€¢ JUnit 4.9: TestRule (@Rule / @ClassRule)
ā€¢ Great for simple use cases
ā€¢ Can even be combined
ā€¢ Butā€¦ a single rule canā€™t be used for method-level and
class-level callbacks
ā€¢ Plusā€¦ zero support for instance-level callbacks
ā€¢ Case in point: SpringClassRule / SpringMethodRule
11
JUnit Lambda
12
Crowdfunding Campaign
ā€¢ Initiated by Johannes Link and
Marc Philipp
ā€¢ Later joined by Matthias Merdes,
Stefan Bechtold, & Sam Brannen
ā€¢ Ran from July to October 2015
ā€¢ Raised 53,937 Euros from 474
individuals and companies
ā€¢ 4 companies donated 6 weeks of
developer time
13
Thanks!
14
The Kick-off Team
15
Roadmap
ā€¢ Prototype ļƒ  December 2nd, 2015
ā€¢ 5.0.0-ALPHA ļƒ  February 1st, 2016
ā€¢ 5.0.0-M1 ļƒ  in progress
ā€“ tentative release end of June 2016
ā€¢ M2, M3, ā€¦ ļƒ  Summer 2016
ā€¢ RC1, RC2, ... ļƒ  Fall 2016
ā€¢ GA ļƒ  late 2016
16
JUnit 5
17
JUnit 5ā€¦ in a Nutshell
ā€¢ Modular
ā€¢ Extensible
ā€¢ Modern
ā€¢ Forward and backward compatible
ā€“ JUnit 5 supports JUnit 3.8 and JUnit 4
ā€“ Can be run with JUnit 4
ā€¢ @RunWith(JUnit5.class)
18
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.
19
Modules
ā€¢ junit5-api
ā€¢ junit-launcher
ā€¢ junit-engine-api
ā€¢ junit5-engine
ā€¢ junit4-engine
ā€¢ junit4-runner
ā€¢ junit-commons
ā€¢ junit-console
ā€¢ junit-gradle
ā€¢ surefire-junit5
20
Launcher API
ā€¢ Used by IDEs and build tools to launch the framework
ā€¢ Central API for discovering and executing tests via one or
more engines
ā€¢ TestDiscoveryRequest
ā€“ selectors and filters
ā€¢ Feedback provided via the TestExecutionListener API
21
TestEngine API
ā€¢ Test engine discovers and executes tests
ā€“ for a particular programming model
ā€¢ Automatic discovery via Javaā€™s ServiceLoader mechanism
ā€¢ JUnit5TestEngine
ā€¢ JUnit4TestEngine
ā€¢ Implement your ownā€¦
22
JUnit 5 Extension Model
org.junit.gen5.api.extensions ļƒ  @ExtendWith(...)
ā€¢ BeforeAllCallback
ā€¢ BeforeEachCallback
ā€¢ BeforeTestExecutionCallback
ā€¢ AfterTestExecutionCallback
ā€¢ AfterEachCallback
ā€¢ AfterAllCallback
ā€¢ ContainerExecutionCondition
ā€¢ TestExecutionCondition
ā€¢ TestInstancePostProcessor
ā€¢ ParameterResolver
ā€¢ TestExecutionExceptionHandler
23
JUnit 5 Programming Model
org.junit.gen5.api
ā€¢ Annotations and meta-annotations
ā€¢ Assertions and Assumptions
ā€¢ Custom display names
ā€¢ Visibility
ā€¢ Tagging
ā€¢ Conditional test execution
ā€¢ Dependency injection for constructors and methods
ā€¢ Lambda expressions and method references
ā€¢ Interface default methods
ā€¢ Nested test classes
24
Annotations
ā€¢ @Test
ā€¢ @BeforeAll / @AfterAll
ā€¢ @BeforeEach / @AfterEach
ā€¢ @DisplayName
ā€¢ @Tag / @Tags
ā€¢ @Disabled
ā€¢ @Nested
25
Assertions
org.junit.gen5.api.Assertions
ā€¢ Limited set of core assertions
ā€“ assertEquals(), assertNotNull(), etc.
ā€“ plus assertThrows() and expectThrows()
ā€“ and assertAll()
ā€¢ Supplier<String> ļƒ  for lazy failure message evaluation
ā€“ message is now the last parameter
ā€¢ For more power, use AssertJ, Hamcrest, etc.
26
Assumptions
org.junit.gen5.api.Assumptions
ā€¢ Limited set of core assumptions
ā€“ For aborting tests mid-flight
ā€¢ assumeTrue() / assumeFalse()
ā€“ BooleanSupplier, Supplier<String>
ā€¢ assumingThat( ? , () -> {} );
27
DEMO
28
Test Names
ā€¢ Names default to test class or test method names
ā€“ characters limited based on Java syntax
ā€¢ Custom display names ļƒ  @DisplayName
ā€“ Can contain spaces, special chars, and even emoji šŸ˜±
29
Dependency Injection
ā€¢ Extension Model meets Programming Model
ā€¢ ParameterResolver extension
ā€“ resolves parameters for constructors or methods
ā€¢ TestInfo: inject into constructor, @Test, @BeforeEach, etc.
ā€“ access display name, tags, class, method
ā€¢ TestInfoParameterResolver
ā€“ eating our own dog food ;-)
ā€¢ See also:
ā€“ TestReporter
ā€“ MockitoExtension
ā€“ SpringExtension
30
DEMO
31
Tagging
ā€¢ Declare @Tag or @Tags on an interface, class, or method
@Tag("fast")
@Test
void myFastTest() {
}
32
Custom Tags
ā€¢ Declare @Tag or @Tags as a meta-annotation
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Tag("fast")
@Test
public @interface FastTest {
}
@FastTest
void myFastTest() {
}
33
Conditional Test Execution
ā€¢ Extension Model meets Programming Model
ā€¢ ContainerExecutionCondition
ā€¢ TestExecutionCondition
ā€¢ @Disabled
ā€¢ DisabledCondition
ā€“ eating our own dog food ;-)
ā€¢ Deactivate via Launcher/System property
ā€“ junit.conditions.deactivate = org.junit.*
34
DEMO
35
Interface Default Methods
ā€¢ Introduces the concept of a test interface
ā€“ Enables multiple inheritance in tests
ā€“ Kinda like testing traits
ā€¢ @BeforeEach / @AfterEach
ā€¢ @Test
ā€¢ @Tag
ā€¢ @ExtendWith
ā€¢ See StringTests example in user guide
36
Nested Test Classes
ā€¢ Enables logical, hierarchical grouping of test classes
ā€“ with shared initialization and state from outer classes
ā€¢ Declare @Nested on non-static nested classes
ā€“ i.e., inner classes
ā€¢ You can even combine nested classes and test interfaces
ā€¢ See TestingAStack example in user guide
37
Spring Support for JUnit 5
ā€¢ SpringExtension
ā€“ @ExtendWith(SpringExtension.class)
ā€“ https://github.com/sbrannen/spring-test-junit5
ā€¢ Works with Spring Framework 4.3
ā€¢ Already supports:
ā€“ Core Spring TestContext Framework features
ā€“ Constructor and method injection via @Autowired,
@Qualifier, @Value
ā€¢ Fully integrated in Spring Framework 5.0
38
DEMO
39
In Closingā€¦
40
Whatā€™s Missing?
ā€¢ Official IDE and build integration
ā€¢ Dynamic tests (M1)
ā€“ registered as lambdas, streams, collections, etc.
ā€¢ Parameterized tests (M2)
ā€¢ Scenario tests (M3)
ā€¢ Parallel execution (?)
ā€¢ ā€¦
41
Resources and Feedback Channels
ā€¢ 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
42
Q & A
Sam Brannen
@sam_brannen
www.slideshare.net/sbrannen
www.swiftmind.com

More Related Content

What's hot

Keyword Driven Testing
Keyword Driven TestingKeyword Driven Testing
Keyword Driven Testing
Maveryx
Ā 

What's hot (20)

JUnit 5 - The Next Generation
JUnit 5 - The Next GenerationJUnit 5 - The Next Generation
JUnit 5 - The Next Generation
Ā 
Spring Test Framework
Spring Test FrameworkSpring Test Framework
Spring Test Framework
Ā 
TDD - Unit Testing
TDD - Unit TestingTDD - Unit Testing
TDD - Unit Testing
Ā 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework
Ā 
Cucumber questions
Cucumber questionsCucumber questions
Cucumber questions
Ā 
Junit5 brujug
Junit5 brujugJunit5 brujug
Junit5 brujug
Ā 
Selenium interview questions
Selenium interview questionsSelenium interview questions
Selenium interview questions
Ā 
Selenium interview-questions-freshers
Selenium interview-questions-freshersSelenium interview-questions-freshers
Selenium interview-questions-freshers
Ā 
Robot framework Gowthami Goli
Robot framework Gowthami GoliRobot framework Gowthami Goli
Robot framework Gowthami Goli
Ā 
Realtime selenium interview questions
Realtime selenium interview questionsRealtime selenium interview questions
Realtime selenium interview questions
Ā 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
Ā 
PL/SQL unit testing with Ruby
PL/SQL unit testing with RubyPL/SQL unit testing with Ruby
PL/SQL unit testing with Ruby
Ā 
Python in Test automation
Python in Test automationPython in Test automation
Python in Test automation
Ā 
JUnit 5
JUnit 5JUnit 5
JUnit 5
Ā 
Integration Group - Lithium test strategy
Integration Group - Lithium test strategyIntegration Group - Lithium test strategy
Integration Group - Lithium test strategy
Ā 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
Ā 
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
Ā 
Keyword Driven Testing
Keyword Driven TestingKeyword Driven Testing
Keyword Driven Testing
Ā 
What is new in JUnit5
What is new in JUnit5What is new in JUnit5
What is new in JUnit5
Ā 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
Ā 

Viewers also liked

JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
Animesh Kumar
Ā 
Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockito
Mathieu Carbou
Ā 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
b_kathir
Ā 
Selenium Webdriver
Selenium WebdriverSelenium Webdriver
Selenium Webdriver
Muhammad Bilal
Ā 

Viewers also liked (20)

JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeJUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
Ā 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
Ā 
Restful web services with java
Restful web services with javaRestful web services with java
Restful web services with java
Ā 
05 junit
05 junit05 junit
05 junit
Ā 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
Ā 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
Ā 
Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockito
Ā 
Maruti Baleno Euro-NCAP result sheet
Maruti Baleno Euro-NCAP result sheetMaruti Baleno Euro-NCAP result sheet
Maruti Baleno Euro-NCAP result sheet
Ā 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
Ā 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
Ā 
Fast ALS-Based Matrix Factorization for Recommender Systems
Fast ALS-Based Matrix Factorization for Recommender SystemsFast ALS-Based Matrix Factorization for Recommender Systems
Fast ALS-Based Matrix Factorization for Recommender Systems
Ā 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
Ā 
Junit
JunitJunit
Junit
Ā 
Test Automation
Test AutomationTest Automation
Test Automation
Ā 
Test Driven Development and JUnit
Test Driven Development and JUnitTest Driven Development and JUnit
Test Driven Development and JUnit
Ā 
API Test Automation Tips and Tricks
API Test Automation Tips and TricksAPI Test Automation Tips and Tricks
API Test Automation Tips and Tricks
Ā 
ą¹‡Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...
ą¹‡Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...ą¹‡Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...
ą¹‡Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...
Ā 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
Ā 
Selenium Webdriver
Selenium WebdriverSelenium Webdriver
Selenium Webdriver
Ā 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
Ā 

Similar to JUnit 5 - from Lambda to Alpha and beyond

Similar to JUnit 5 - from Lambda to Alpha and beyond (20)

JUnit 5 Slides: Next generation Framework for Testing
JUnit 5 Slides: Next generation Framework for TestingJUnit 5 Slides: Next generation Framework for Testing
JUnit 5 Slides: Next generation Framework for Testing
Ā 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An Introduction
Ā 
Spring Framework 3.2 - What's New
Spring Framework 3.2 - What's NewSpring Framework 3.2 - What's New
Spring Framework 3.2 - What's New
Ā 
Testing Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsTesting Spring MVC and REST Web Applications
Testing Spring MVC and REST Web Applications
Ā 
Effective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and DapperEffective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and Dapper
Ā 
There's more to Ratpack than non-blocking
There's more to Ratpack than non-blockingThere's more to Ratpack than non-blocking
There's more to Ratpack than non-blocking
Ā 
Effective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and DapperEffective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and Dapper
Ā 
MIGRATION - PAIN OR GAIN?
MIGRATION - PAIN OR GAIN?MIGRATION - PAIN OR GAIN?
MIGRATION - PAIN OR GAIN?
Ā 
Automated testing 101
Automated testing 101Automated testing 101
Automated testing 101
Ā 
Test planning and software's engineering
Test planning and software's engineeringTest planning and software's engineering
Test planning and software's engineering
Ā 
Salesforce Continuous Integration with AutoRABIT
Salesforce Continuous Integration with AutoRABITSalesforce Continuous Integration with AutoRABIT
Salesforce Continuous Integration with AutoRABIT
Ā 
Protractor survival guide
Protractor survival guideProtractor survival guide
Protractor survival guide
Ā 
Context Driven Automation Gtac 2008
Context Driven Automation Gtac 2008Context Driven Automation Gtac 2008
Context Driven Automation Gtac 2008
Ā 
Agile Testing Introduction
Agile Testing IntroductionAgile Testing Introduction
Agile Testing Introduction
Ā 
Nyenrode Masterclass 'DevOps unraveled' Apr 18, 2016
Nyenrode Masterclass 'DevOps unraveled' Apr 18, 2016Nyenrode Masterclass 'DevOps unraveled' Apr 18, 2016
Nyenrode Masterclass 'DevOps unraveled' Apr 18, 2016
Ā 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
Ā 
KrishnaToolComparisionPPT.pdf
KrishnaToolComparisionPPT.pdfKrishnaToolComparisionPPT.pdf
KrishnaToolComparisionPPT.pdf
Ā 
It's all about feedback - code review as a great tool in the agile toolbox
It's all about feedback - code review as a great tool in the agile toolboxIt's all about feedback - code review as a great tool in the agile toolbox
It's all about feedback - code review as a great tool in the agile toolbox
Ā 
Gerrit + Jenkins = Continuous Delivery For Big Data
Gerrit + Jenkins = Continuous Delivery For Big DataGerrit + Jenkins = Continuous Delivery For Big Data
Gerrit + Jenkins = Continuous Delivery For Big Data
Ā 
Parser Breakout Session
Parser Breakout SessionParser Breakout Session
Parser Breakout Session
Ā 

More from Sam Brannen

Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2
Sam Brannen
Ā 

More from Sam Brannen (19)

Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Ā 
Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022
Ā 
Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2
Ā 
Composable Software Architecture with Spring
Composable Software Architecture with SpringComposable Software Architecture with Spring
Composable Software Architecture with Spring
Ā 
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2
Ā 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1
Ā 
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Ā 
Spring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4DevelopersSpring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4Developers
Ā 
Effective out-of-container Integration Testing - 4Developers
Effective out-of-container Integration Testing - 4DevelopersEffective out-of-container Integration Testing - 4Developers
Effective out-of-container Integration Testing - 4Developers
Ā 
Spring 3.1 to 3.2 in a Nutshell - SDC2012
Spring 3.1 to 3.2 in a Nutshell - SDC2012Spring 3.1 to 3.2 in a Nutshell - SDC2012
Spring 3.1 to 3.2 in a Nutshell - SDC2012
Ā 
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Ā 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing Support
Ā 
Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011
Ā 
Spring 3.1 in a Nutshell
Spring 3.1 in a NutshellSpring 3.1 in a Nutshell
Spring 3.1 in a Nutshell
Ā 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
Ā 
Effective out-of-container Integration Testing
Effective out-of-container Integration TestingEffective out-of-container Integration Testing
Effective out-of-container Integration Testing
Ā 
What's New in Spring 3.0
What's New in Spring 3.0What's New in Spring 3.0
What's New in Spring 3.0
Ā 
Modular Web Applications with OSGi
Modular Web Applications with OSGiModular Web Applications with OSGi
Modular Web Applications with OSGi
Ā 
Enterprise Applications With OSGi and SpringSource dm Server
Enterprise Applications With OSGi and SpringSource dm ServerEnterprise Applications With OSGi and SpringSource dm Server
Enterprise Applications With OSGi and SpringSource dm Server
Ā 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
Ā 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
Ā 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
Ā 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
Ā 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
Ā 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
Ā 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Bert Jan Schrijver
Ā 

Recently uploaded (20)

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
Ā 
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
Ā 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
Ā 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
Ā 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
Ā 
call girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļøcall girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
Ā 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
Ā 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
Ā 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
Ā 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Ā 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
Ā 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
Ā 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
Ā 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
Ā 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
Ā 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Ā 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
Ā 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
Ā 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
Ā 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Ā 

JUnit 5 - from Lambda to Alpha and beyond

  • 1. from Lambda to Alpha and Beyond ā€¦ Sam Brannen @sam_brannen JUnit
  • 2. 2 Sam Brannen ā€¢ Spring and Java Consultant @ ā€¢ Java Developer for over 17 years ā€¢ Spring Framework Core Committer since 2007 ā€¢ Swiss Spring User Group Lead ā€¢ Trainer & Conference Speaker ā€¢ JUnit 5 Core Committer since October 2015
  • 3. 3 Swiftmind Experts in Spring and Enterprise Java Areas of expertise ā€¢ Spring * ā€¢ Java EE ā€¢ Software Architecture ā€¢ Software Development Where you find us ā€¢ Zurich, Switzerland ā€¢ @swiftmind ā€¢ http://www.swiftmind.com
  • 4. 4 A Show of Handsā€¦
  • 5. 5 Agenda ā€¢ Impetus for Change ā€¢ JUnit Lambda ā€¢ Roadmap ā€¢ JUnit 5 ā€¢ Feedback ā€¢ Q&A
  • 7. 7 Why a New Version of JUnit? ā€¢ JUnit 4.0 was released a decade ago ā€“ a lot has changed since thenā€¦ ā€“ testing needs have matured ā€“ expectations have grown ā€¢ Modularity ļƒ  big ball of mud ā€¢ Test discovery and execution ļƒ  tightly coupled ā€¢ Extensibility ļƒ  lot of room for improvement ā€¢ Letā€™s not forget Java 8
  • 8. 8 Modularity in JUnit 4 ā€¢ Sure there are packages ā€“ butā€¦ thereā€™s only THE junit.jar
  • 9. 9 JUnit 4 Runner API ā€¢ Very powerful ā€¢ In fact, it can do anything ā€¢ Butā€¦ you canā€™t combine Runners ā€¢ Parameterized + SpringJUnit4ClassRunner ļƒ  no way
  • 10. 10 JUnit 4ā€¦ Rulesā€¦ are meant to be broken ā€¢ JUnit 4.7: MethodRule (@Rule) ā€¢ JUnit 4.9: TestRule (@Rule / @ClassRule) ā€¢ Great for simple use cases ā€¢ Can even be combined ā€¢ Butā€¦ a single rule canā€™t be used for method-level and class-level callbacks ā€¢ Plusā€¦ zero support for instance-level callbacks ā€¢ Case in point: SpringClassRule / SpringMethodRule
  • 12. 12 Crowdfunding Campaign ā€¢ Initiated by Johannes Link and Marc Philipp ā€¢ Later joined by Matthias Merdes, Stefan Bechtold, & Sam Brannen ā€¢ Ran from July to October 2015 ā€¢ Raised 53,937 Euros from 474 individuals and companies ā€¢ 4 companies donated 6 weeks of developer time
  • 15. 15 Roadmap ā€¢ Prototype ļƒ  December 2nd, 2015 ā€¢ 5.0.0-ALPHA ļƒ  February 1st, 2016 ā€¢ 5.0.0-M1 ļƒ  in progress ā€“ tentative release end of June 2016 ā€¢ M2, M3, ā€¦ ļƒ  Summer 2016 ā€¢ RC1, RC2, ... ļƒ  Fall 2016 ā€¢ GA ļƒ  late 2016
  • 17. 17 JUnit 5ā€¦ in a Nutshell ā€¢ Modular ā€¢ Extensible ā€¢ Modern ā€¢ Forward and backward compatible ā€“ JUnit 5 supports JUnit 3.8 and JUnit 4 ā€“ Can be run with JUnit 4 ā€¢ @RunWith(JUnit5.class)
  • 18. 18 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.
  • 19. 19 Modules ā€¢ junit5-api ā€¢ junit-launcher ā€¢ junit-engine-api ā€¢ junit5-engine ā€¢ junit4-engine ā€¢ junit4-runner ā€¢ junit-commons ā€¢ junit-console ā€¢ junit-gradle ā€¢ surefire-junit5
  • 20. 20 Launcher API ā€¢ Used by IDEs and build tools to launch the framework ā€¢ Central API for discovering and executing tests via one or more engines ā€¢ TestDiscoveryRequest ā€“ selectors and filters ā€¢ Feedback provided via the TestExecutionListener API
  • 21. 21 TestEngine API ā€¢ Test engine discovers and executes tests ā€“ for a particular programming model ā€¢ Automatic discovery via Javaā€™s ServiceLoader mechanism ā€¢ JUnit5TestEngine ā€¢ JUnit4TestEngine ā€¢ Implement your ownā€¦
  • 22. 22 JUnit 5 Extension Model org.junit.gen5.api.extensions ļƒ  @ExtendWith(...) ā€¢ BeforeAllCallback ā€¢ BeforeEachCallback ā€¢ BeforeTestExecutionCallback ā€¢ AfterTestExecutionCallback ā€¢ AfterEachCallback ā€¢ AfterAllCallback ā€¢ ContainerExecutionCondition ā€¢ TestExecutionCondition ā€¢ TestInstancePostProcessor ā€¢ ParameterResolver ā€¢ TestExecutionExceptionHandler
  • 23. 23 JUnit 5 Programming Model org.junit.gen5.api ā€¢ Annotations and meta-annotations ā€¢ Assertions and Assumptions ā€¢ Custom display names ā€¢ Visibility ā€¢ Tagging ā€¢ Conditional test execution ā€¢ Dependency injection for constructors and methods ā€¢ Lambda expressions and method references ā€¢ Interface default methods ā€¢ Nested test classes
  • 24. 24 Annotations ā€¢ @Test ā€¢ @BeforeAll / @AfterAll ā€¢ @BeforeEach / @AfterEach ā€¢ @DisplayName ā€¢ @Tag / @Tags ā€¢ @Disabled ā€¢ @Nested
  • 25. 25 Assertions org.junit.gen5.api.Assertions ā€¢ Limited set of core assertions ā€“ assertEquals(), assertNotNull(), etc. ā€“ plus assertThrows() and expectThrows() ā€“ and assertAll() ā€¢ Supplier<String> ļƒ  for lazy failure message evaluation ā€“ message is now the last parameter ā€¢ For more power, use AssertJ, Hamcrest, etc.
  • 26. 26 Assumptions org.junit.gen5.api.Assumptions ā€¢ Limited set of core assumptions ā€“ For aborting tests mid-flight ā€¢ assumeTrue() / assumeFalse() ā€“ BooleanSupplier, Supplier<String> ā€¢ assumingThat( ? , () -> {} );
  • 28. 28 Test Names ā€¢ Names default to test class or test method names ā€“ characters limited based on Java syntax ā€¢ Custom display names ļƒ  @DisplayName ā€“ Can contain spaces, special chars, and even emoji šŸ˜±
  • 29. 29 Dependency Injection ā€¢ Extension Model meets Programming Model ā€¢ ParameterResolver extension ā€“ resolves parameters for constructors or methods ā€¢ TestInfo: inject into constructor, @Test, @BeforeEach, etc. ā€“ access display name, tags, class, method ā€¢ TestInfoParameterResolver ā€“ eating our own dog food ;-) ā€¢ See also: ā€“ TestReporter ā€“ MockitoExtension ā€“ SpringExtension
  • 31. 31 Tagging ā€¢ Declare @Tag or @Tags on an interface, class, or method @Tag("fast") @Test void myFastTest() { }
  • 32. 32 Custom Tags ā€¢ Declare @Tag or @Tags as a meta-annotation @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Tag("fast") @Test public @interface FastTest { } @FastTest void myFastTest() { }
  • 33. 33 Conditional Test Execution ā€¢ Extension Model meets Programming Model ā€¢ ContainerExecutionCondition ā€¢ TestExecutionCondition ā€¢ @Disabled ā€¢ DisabledCondition ā€“ eating our own dog food ;-) ā€¢ Deactivate via Launcher/System property ā€“ junit.conditions.deactivate = org.junit.*
  • 35. 35 Interface Default Methods ā€¢ Introduces the concept of a test interface ā€“ Enables multiple inheritance in tests ā€“ Kinda like testing traits ā€¢ @BeforeEach / @AfterEach ā€¢ @Test ā€¢ @Tag ā€¢ @ExtendWith ā€¢ See StringTests example in user guide
  • 36. 36 Nested Test Classes ā€¢ Enables logical, hierarchical grouping of test classes ā€“ with shared initialization and state from outer classes ā€¢ Declare @Nested on non-static nested classes ā€“ i.e., inner classes ā€¢ You can even combine nested classes and test interfaces ā€¢ See TestingAStack example in user guide
  • 37. 37 Spring Support for JUnit 5 ā€¢ SpringExtension ā€“ @ExtendWith(SpringExtension.class) ā€“ https://github.com/sbrannen/spring-test-junit5 ā€¢ Works with Spring Framework 4.3 ā€¢ Already supports: ā€“ Core Spring TestContext Framework features ā€“ Constructor and method injection via @Autowired, @Qualifier, @Value ā€¢ Fully integrated in Spring Framework 5.0
  • 40. 40 Whatā€™s Missing? ā€¢ Official IDE and build integration ā€¢ Dynamic tests (M1) ā€“ registered as lambdas, streams, collections, etc. ā€¢ Parameterized tests (M2) ā€¢ Scenario tests (M3) ā€¢ Parallel execution (?) ā€¢ ā€¦
  • 41. 41 Resources and Feedback Channels ā€¢ 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
  • 42. 42 Q & A Sam Brannen @sam_brannen www.slideshare.net/sbrannen www.swiftmind.com