SlideShare una empresa de Scribd logo
1 de 14
Migrating to
JUnit 5 (alpha)
JUnit 4 JUnit 5
import org.junit.Test;
public class JUnit4Test {
@Test
public void aJunit4TestCase() {
// write test here
}
}
import org.junit.gen5.api.Test;
class JUnit5Test {
@Test
void aJunit5TestCase() {
// write test here
}
}
public @interface Test {
Class<? extends Throwable>
expected() default None.class;
long timeout() default 0L;
}
JUnit 4 JUnit 5
public @interface Test {
}
public @interface Before {}
public @interface After {}
public @interface BeforeEach {}
public @interface AfterEach {}
public @interface BeforeClass {}
public @interface AfterClass {}
public @interface BeforeAll {}
public @interface AfterAll {}
public @interface Ignore {
String value() default "";
}
public @interface Disabled {
String value() default "";
}
class FunctionalAssertionsWithHamcrest {
@Test
void testProcedural() {
File file = new File("/some/property.file");
assertTrue(file.exists());
}
@Test
void testFunctional() {
File file = new File("/some/property.file");
assertTrue(file::exists);
}
@Test
void testFunctionalGrouped() {
File file = new File("/some/property.file");
assertAll(() -> file.canWrite(), () -> file.canRead());
}
}
class AssumptionsAndExceptions {
@Test
void testFullyConditional() {
File file = new File("/some/property.file");
assumeTrue(file.exists());
runSomeRoutineDependingOn(file);
}
@Test
void testPartlyConditional() {
File file = new File("/some/property.file");
assumingThat(file.exists()), () -> {
runSomeRoutineDependingOn(file);
});
}
@Test
void testThrowsExcption() {
IOException exception = expectThrows(IOException.class, () -> {
new File("?").getCanonicalPath();
});
validate(exception);
}
}
JUnit 4 JUnit 5
public class ATest {
@Test
public void foo() {}
}
public class BTest {
@Test
public void bar() {}
}
@RunWith(Suite.class)
@Suite.SuiteClasses({
ATest.class,
BTest.class
})
public class MySuite {}
@Tag(SuiteA.class)
public class ATest {
@Test
public void foo() {}
}
@Tags(
@Tag(SuiteA.class),
@Tag(SuiteB.class)
)
public class BTest {
@Test
public void bar() {}
}
JUnit 4 JUnit 5
public class ATest {
@Test
public void foo() {}
}
public class BTest {
@Test
public void bar() {}
}
@RunWith(Suite.class)
@Suite.SuiteClasses({
ATest.class,
BTest.class
})
public class MySuite {}
@Tag(SuiteA.class)
public class ATest {
@Test
public void foo() {}
}
@Tag(SuiteA.class)
@Tag(SuiteB.class)
@Retention(RUNTIME)
public @interface Meta {}
@Meta
public class BTest {
@Test
public void bar() {}
}
@DisplayName("A stack")
class TestingAStack {
Stack<Object> stack = new Stack<Object>();
@Test @DisplayName("is empty") void isEmpty() {
Assertions.assertTrue(stack.isEmpty());
}
@Nested @DisplayName("after pushing an element")
class AfterPushing {
String anElement = "an element";
@BeforeEach void init() {
stack.push(anElement);
}
@Test @DisplayName("it is no longer empty") void isEmpty() {
Assertions.assertFalse(stack.isEmpty());
}
@Test @DisplayName("returns the element when popped")
void returnElementWhenPopped() {
Assertions.assertEquals(anElement, stack.pop());
}
}
}
class DependencyInjection {
@Test
void testSelfAware(TestInfo testInfo) {
String name = testInfo.getName();
assertTrue("selfAwareTest", name);
}
}
public interface TestInfo {
String getName();
String getDisplayName();
Set<String> getTags();
}
class DependencyInjection {
@Test
void testSelfReport(TestReporter testReporter) {
long start = System.nanoTime();
doHeavyLifting();
testReporter.publishEntry("time", System.nanoTime() - start);
}
}
public interface TestReporter {
void publishEntry(String key, String value);
void publishEntry(Map<String, String> values);
}
JUnit 4 JUnit 5
public @interface Rule {
String value() default "";
}
public @interface RunWith {
Class<? extends Runner> value();
}
public @interface ExtendWith {
Class<? extends Extension>[]
value();
}
interface ContainerExecutionCondition {...}
interface TestExecutionCondition { ... }
interface BeforeAllExtensionPoint { ... }
interface BeforeEachExtensionPoint { ... }
interface InstancePostProcessor { ... }
interface MethodParameterResolver { ... }
interface ExceptionHandlerExtensionPoint { ... }
interface AfterEachExtensionPoint { ... }
interface AfterAllExtensionPoint { ... }
@ExtendWith(FooExtension.class)
class FunctionalAssertionsWithHamcrest {
@Test
void testProcedural(@Foo File file) {
assertTrue(file.exists());
}
}
@Retention(RUNTIME)
@interface Foo {}
class FooExtension implements MethodParameterResolver {
@Override public boolean supports(Parameter parameter,
MethodInvocationContext methodInvocationContext,
ExtensionContext extensionContext) {
return parameter.isAnnotationPresent(Foo.class);
}
@Override public Object resolve(Parameter parameter,
MethodInvocationContext methodInvocationContext,
ExtensionContext extensionContext){
return new File("some/file");
}
}
Currently still unsupported:
1. Parameterized tests (no test-runner equivalent)
2. No test-timeout
3. No sorting of test methods
JInit 5 is work-in-progress and the development has slowed
down significantly. Tickets for M1 are up-for-grab on GitHub!
http://rafael.codes
@rafaelcodes
http://documents4j.com
https://github.com/documents4j/documents4j
http://bytebuddy.net
https://github.com/raphw/byte-buddy

Más contenido relacionado

La actualidad más candente

TDD? Sure, but What About My Legacy Code?
TDD? Sure, but What About My Legacy Code?TDD? Sure, but What About My Legacy Code?
TDD? Sure, but What About My Legacy Code?Rob Myers
 
Generating characterization tests for legacy code
Generating characterization tests for legacy codeGenerating characterization tests for legacy code
Generating characterization tests for legacy codeJonas Follesø
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesGanesh Samarthyam
 
Easy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEEasy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEUehara Junji
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleAnton Arhipov
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW SydneySoftware Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydneyjulien.ponge
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...julien.ponge
 
Exception Handling
Exception HandlingException Handling
Exception HandlingSunil OS
 
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Uehara Junji
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test frameworkAbner Chih Yi Huang
 

La actualidad más candente (20)

TDD? Sure, but What About My Legacy Code?
TDD? Sure, but What About My Legacy Code?TDD? Sure, but What About My Legacy Code?
TDD? Sure, but What About My Legacy Code?
 
Lambda Functions in Java 8
Lambda Functions in Java 8Lambda Functions in Java 8
Lambda Functions in Java 8
 
Server1
Server1Server1
Server1
 
Generating characterization tests for legacy code
Generating characterization tests for legacy codeGenerating characterization tests for legacy code
Generating characterization tests for legacy code
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
 
Java programs
Java programsJava programs
Java programs
 
Easy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEEasy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVE
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassle
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Lab4
Lab4Lab4
Lab4
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW SydneySoftware Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydney
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
 
Java 7 LavaJUG
Java 7 LavaJUGJava 7 LavaJUG
Java 7 LavaJUG
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test framework
 
Mockito intro
Mockito introMockito intro
Mockito intro
 

Similar a Migrating to JUnit 5

Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testingjeresig
 
Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4jeresig
 
Java Serialization
Java SerializationJava Serialization
Java Serializationjeslie
 
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 TimeTed Vinke
 
Implement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfImplement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfSIGMATAX1
 
Unittesting JavaScript with Evidence
Unittesting JavaScript with EvidenceUnittesting JavaScript with Evidence
Unittesting JavaScript with EvidenceTobie Langel
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdffathimafancyjeweller
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfNicholasflqStewartl
 
Description (Part A) In this lab you will write a Queue implementati.pdf
Description (Part A) In this lab you will write a Queue implementati.pdfDescription (Part A) In this lab you will write a Queue implementati.pdf
Description (Part A) In this lab you will write a Queue implementati.pdfrishabjain5053
 
How to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeHow to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeDaniel Wellman
 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docxBlakeSGMHemmingss
 
Java Generics
Java GenericsJava Generics
Java Genericsjeslie
 
Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Chang W. Doh
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 

Similar a Migrating to JUnit 5 (20)

JUnit 5
JUnit 5JUnit 5
JUnit 5
 
3 j unit
3 j unit3 j unit
3 j unit
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testing
 
Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4
 
Junit 5 - Maior e melhor
Junit 5 - Maior e melhorJunit 5 - Maior e melhor
Junit 5 - Maior e melhor
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
 
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
 
Implement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfImplement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdf
 
Unittesting JavaScript with Evidence
Unittesting JavaScript with EvidenceUnittesting JavaScript with Evidence
Unittesting JavaScript with Evidence
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdf
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
 
Description (Part A) In this lab you will write a Queue implementati.pdf
Description (Part A) In this lab you will write a Queue implementati.pdfDescription (Part A) In this lab you will write a Queue implementati.pdf
Description (Part A) In this lab you will write a Queue implementati.pdf
 
How to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeHow to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy Code
 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docx
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
Tdd
TddTdd
Tdd
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 

Más de Rafael Winterhalter

Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemRafael Winterhalter
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agentsRafael Winterhalter
 
Event-Sourcing Microservices on the JVM
Event-Sourcing Microservices on the JVMEvent-Sourcing Microservices on the JVM
Event-Sourcing Microservices on the JVMRafael Winterhalter
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modulesRafael Winterhalter
 
Monitoring distributed (micro-)services
Monitoring distributed (micro-)servicesMonitoring distributed (micro-)services
Monitoring distributed (micro-)servicesRafael Winterhalter
 
An introduction to JVM performance
An introduction to JVM performanceAn introduction to JVM performance
An introduction to JVM performanceRafael Winterhalter
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMRafael Winterhalter
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVMRafael Winterhalter
 

Más de Rafael Winterhalter (12)

Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystem
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agents
 
Event-Sourcing Microservices on the JVM
Event-Sourcing Microservices on the JVMEvent-Sourcing Microservices on the JVM
Event-Sourcing Microservices on the JVM
 
Java 10, Java 11 and beyond
Java 10, Java 11 and beyondJava 10, Java 11 and beyond
Java 10, Java 11 and beyond
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modules
 
Monitoring distributed (micro-)services
Monitoring distributed (micro-)servicesMonitoring distributed (micro-)services
Monitoring distributed (micro-)services
 
An Overview of Project Jigsaw
An Overview of Project JigsawAn Overview of Project Jigsaw
An Overview of Project Jigsaw
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
 
An introduction to JVM performance
An introduction to JVM performanceAn introduction to JVM performance
An introduction to JVM performance
 
Java byte code in practice
Java byte code in practiceJava byte code in practice
Java byte code in practice
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 

Último

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 

Último (20)

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Migrating to JUnit 5

  • 2. JUnit 4 JUnit 5 import org.junit.Test; public class JUnit4Test { @Test public void aJunit4TestCase() { // write test here } } import org.junit.gen5.api.Test; class JUnit5Test { @Test void aJunit5TestCase() { // write test here } }
  • 3. public @interface Test { Class<? extends Throwable> expected() default None.class; long timeout() default 0L; } JUnit 4 JUnit 5 public @interface Test { } public @interface Before {} public @interface After {} public @interface BeforeEach {} public @interface AfterEach {} public @interface BeforeClass {} public @interface AfterClass {} public @interface BeforeAll {} public @interface AfterAll {} public @interface Ignore { String value() default ""; } public @interface Disabled { String value() default ""; }
  • 4. class FunctionalAssertionsWithHamcrest { @Test void testProcedural() { File file = new File("/some/property.file"); assertTrue(file.exists()); } @Test void testFunctional() { File file = new File("/some/property.file"); assertTrue(file::exists); } @Test void testFunctionalGrouped() { File file = new File("/some/property.file"); assertAll(() -> file.canWrite(), () -> file.canRead()); } }
  • 5. class AssumptionsAndExceptions { @Test void testFullyConditional() { File file = new File("/some/property.file"); assumeTrue(file.exists()); runSomeRoutineDependingOn(file); } @Test void testPartlyConditional() { File file = new File("/some/property.file"); assumingThat(file.exists()), () -> { runSomeRoutineDependingOn(file); }); } @Test void testThrowsExcption() { IOException exception = expectThrows(IOException.class, () -> { new File("?").getCanonicalPath(); }); validate(exception); } }
  • 6. JUnit 4 JUnit 5 public class ATest { @Test public void foo() {} } public class BTest { @Test public void bar() {} } @RunWith(Suite.class) @Suite.SuiteClasses({ ATest.class, BTest.class }) public class MySuite {} @Tag(SuiteA.class) public class ATest { @Test public void foo() {} } @Tags( @Tag(SuiteA.class), @Tag(SuiteB.class) ) public class BTest { @Test public void bar() {} }
  • 7. JUnit 4 JUnit 5 public class ATest { @Test public void foo() {} } public class BTest { @Test public void bar() {} } @RunWith(Suite.class) @Suite.SuiteClasses({ ATest.class, BTest.class }) public class MySuite {} @Tag(SuiteA.class) public class ATest { @Test public void foo() {} } @Tag(SuiteA.class) @Tag(SuiteB.class) @Retention(RUNTIME) public @interface Meta {} @Meta public class BTest { @Test public void bar() {} }
  • 8. @DisplayName("A stack") class TestingAStack { Stack<Object> stack = new Stack<Object>(); @Test @DisplayName("is empty") void isEmpty() { Assertions.assertTrue(stack.isEmpty()); } @Nested @DisplayName("after pushing an element") class AfterPushing { String anElement = "an element"; @BeforeEach void init() { stack.push(anElement); } @Test @DisplayName("it is no longer empty") void isEmpty() { Assertions.assertFalse(stack.isEmpty()); } @Test @DisplayName("returns the element when popped") void returnElementWhenPopped() { Assertions.assertEquals(anElement, stack.pop()); } } }
  • 9. class DependencyInjection { @Test void testSelfAware(TestInfo testInfo) { String name = testInfo.getName(); assertTrue("selfAwareTest", name); } } public interface TestInfo { String getName(); String getDisplayName(); Set<String> getTags(); }
  • 10. class DependencyInjection { @Test void testSelfReport(TestReporter testReporter) { long start = System.nanoTime(); doHeavyLifting(); testReporter.publishEntry("time", System.nanoTime() - start); } } public interface TestReporter { void publishEntry(String key, String value); void publishEntry(Map<String, String> values); }
  • 11. JUnit 4 JUnit 5 public @interface Rule { String value() default ""; } public @interface RunWith { Class<? extends Runner> value(); } public @interface ExtendWith { Class<? extends Extension>[] value(); } interface ContainerExecutionCondition {...} interface TestExecutionCondition { ... } interface BeforeAllExtensionPoint { ... } interface BeforeEachExtensionPoint { ... } interface InstancePostProcessor { ... } interface MethodParameterResolver { ... } interface ExceptionHandlerExtensionPoint { ... } interface AfterEachExtensionPoint { ... } interface AfterAllExtensionPoint { ... }
  • 12. @ExtendWith(FooExtension.class) class FunctionalAssertionsWithHamcrest { @Test void testProcedural(@Foo File file) { assertTrue(file.exists()); } } @Retention(RUNTIME) @interface Foo {} class FooExtension implements MethodParameterResolver { @Override public boolean supports(Parameter parameter, MethodInvocationContext methodInvocationContext, ExtensionContext extensionContext) { return parameter.isAnnotationPresent(Foo.class); } @Override public Object resolve(Parameter parameter, MethodInvocationContext methodInvocationContext, ExtensionContext extensionContext){ return new File("some/file"); } }
  • 13. Currently still unsupported: 1. Parameterized tests (no test-runner equivalent) 2. No test-timeout 3. No sorting of test methods JInit 5 is work-in-progress and the development has slowed down significantly. Tickets for M1 are up-for-grab on GitHub!