Noopur Gupta Eclipse JDT co-lead IBM India noopur_gupta@in.ibm.com
Embracing with
1
@noopur2507
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
Embracing Noopur Gupta Eclipse JDT co-lead IBM India with - - PowerPoint PPT Presentation
Embracing Noopur Gupta Eclipse JDT co-lead IBM India with noopur_gupta@in.ibm.com @noopur2507 1 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM JUnit Framework JUnit 4.0 Released in 2006 JUnit 5.0
Noopur Gupta Eclipse JDT co-lead IBM India noopur_gupta@in.ibm.com
1
@noopur2507
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
JUnit 4.0
Released in 2006
JUnit 5.0
Released in September 2017
2
Source: http://blog.takipi.com/the-top-100-java-libraries-in-2017-based-on-259885-source-files/
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
The top 20 Java libraries on GitHub in 2017
Modularity (single JAR) Developers accessing internals and duplicating code Maintainability Extensibility
(via Runners and Rules)
Java 8 support
(Lambdas, Streams, Default Methods etc.)
3
junit.jar (Single JUnit 4 JAR) Testing frameworks developers Build tools developers IDEs developers @Test developers
Problems
(+ org.hamcrest.core.jar)
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
4
JUnit 5 = Platform + Jupiter + Vintage
5th planet in Solar System!
Source: http://junit.org/junit5/docs/current/user-guide/#dependency-diagram
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
5
JUnit Platform
▪ junit-platform-launcher Launcher APIs used by IDEs and build tools to launch the framework. Finds test engines via Java’s ServiceLoader mechanism. ▪ junit-platform-engine TestEngine APIs for integration of any testing framework that runs on platform.
JUnit Jupiter
▪ junit-jupiter-api APIs for the new programming and extension model. ▪ junit-jupiter-engine JupiterTestEngine - To discover and execute Jupiter tests.
JUnit Vintage
▪ junit-vintage-engine To discover and execute JUnit 3 and JUnit 4 tests on JUnit 5 platform.
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
A sneak peek into the major interesting features of JUnit Jupiter with Eclipse support for JUnit 5.
6 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
7
Eclipse Oxygen.1a (4.7.1a)
https://www.eclipse.org/downloads/eclipse-packages
Eclipse Photon (4.8) M2 onwards
http://download.eclipse.org/eclipse/downloads
Software site repository to update Eclipse Oxygen (4.7 and 4.7.1):
http://download.eclipse.org/releases/oxygen/
Demo: Eclipse Photon (4.8) M2 milestone build
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
8 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
Create a new JUnit Jupiter test
Create a new JUnit Jupiter test in Eclipse with lifecycle method stubs for a class and its methods under test:
9
New JUnit Test Case wizard
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
Add JUnit 5 library to the build path
10
New JUnit Test Case wizard offers to add it while creating a new JUnit Jupiter test. Quick Fix (Ctrl+1) proposal on @Test. Add library (JUnit) in Java Build Path dialog.
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
11
Visibility
Test classes and methods can have any access modifier (other than private).
Annotations
JUnit 4 JUnit Jupiter @org.junit.Test @org.junit.jupiter.api.Test
(No expected and timeout attributes)
@BeforeClass @BeforeAll @AfterClass @AfterAll @Before @BeforeEach @After @AfterEach @Ignore @Disabled
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
Create a JUnit Jupiter test method in Eclipse with the new template:
12
test_jupiter
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
Create a new JUnit Jupiter test method
13
Assertions
(org.junit.jupiter.api.Assertions class)
and then report all failures together.
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
14
(org.junit.jupiter.api.Assumptions class)
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
Assumptions
JUnit Jupiter’s Assertions, Assumptions, DynamicContainer & DynamicTest classes are now added to Eclipse Favorites by default.
15
Preferences
Import static methods in your code from favorite classes via Content Assist (Ctrl + Space) and Quick Fix (Ctrl + 1). Configure the number of static member imports needed before type.* is used.
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
Eclipse Favorites
16
@DisplayName
Provide custom display names for test classes and test methods - with spaces, special characters, and even emojis! Use Go to File action or just double-click to navigate to the test from JUnit view.
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
17
@Nested test classes
Non-static nested classes (i.e. inner classes) can serve as @Nested tests for logical grouping of test cases.
(Re-)Run a single @Nested test class by using the Run action in JUnit view or Outline view. You can even right-click on a nested test class name in the editor and use the Run As action.
Example: TestingAStackDemo in JUnit 5 user guide.
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
18
Test interfaces and default methods
Example: StringTests in JUnit 5 user guide.
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
19
Tagging and Filtering
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
Provide tags to be included in
via Configure Tags dialog in its JUnit launch configuration.
20
Meta-annotations and composed annotations
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
21
Dynamic Tests
Create a @TestFactory method in Eclipse with the new template:
test_factory
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
There are no lifecycle callbacks for individual dynamic tests.
22
Navigate to failing source location
Double-click an entry in JUnit view’s failure trace to jump to the corresponding source location. Click "Show Stack Trace in Console View" button and use the hyperlinks. It can also be used to copy parts of the stack trace.
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
23
Dependency Injection
Dependency Injection.
dynamically resolves a parameter at runtime.
currently executing test:
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
24
Dependency Injection
from the currently executing test which can be seen in the Console view in Eclipse:
launch configuration now shows the method parameter types also:
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
25
Repeated Tests
Repeat a test by annotating the method with @RepeatedTest and specifying the number of repetitions.
repetition.
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
26
Parameterized Tests
Run a test multiple times with different arguments by:
ParameterResolvers at the end of the method's parameter list.
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
27
Test Instance Lifecycle
executing each test method.
annotate the test class with @TestInstance(Lifecycle.PER_CLASS).
annotations on:
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
See the JUnit 5 User Guide for more details.
28
Provides extension points as interfaces in org.junit.jupiter.api.extension package to be implemented by extension providers. Register one or more extensions declaratively on a test class, test method,
JUnit Jupiter also supports global extension registration via Java’s ServiceLoader mechanism.
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
29
Modular architecture Modern programming model Powerful extension model Gentle migration path Eclipse IDE support
EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
Eclipse support for JUnit 5
https://www.eclipse.org/community/eclipse_newsletter/2017/october/article5.php Download Photon (4.8) M2 & above: http://download.eclipse.org/eclipse/downloads Download Oxygen.1a (4.7.1a): https://www.eclipse.org/downloads/eclipse-packages Software site to update Oxygen (4.7 & 4.7.1): http://download.eclipse.org/releases/oxygen/ Report bugs/enhancements: https://bugs.eclipse.org/bugs/enter_bug.cgi?product=JDT
30 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
JUnit 5 Project
http://junit.org/junit5 User Guide http://junit.org/junit5/docs/current/user-guide Javadoc http://junit.org/junit5/docs/current/api GitHub https://github.com/junit-team/junit5 Gitter https://gitter.im/junit-team/junit5 Q&A http://stackoverflow.com/questions/tagged/junit5
31 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
32 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
33 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM
Eclipse Converge 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM 34 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM