embracing
play

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


  1. 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

  2. JUnit Framework  JUnit 4.0 Released in 2006  JUnit 5.0 Released in September 2017 The top 20 Java libraries on GitHub in 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

  3. JUnit 4 Architecture Problems Modularity (single JAR) @Test developers Developers accessing internals and duplicating code IDEs developers junit.jar (Single JUnit 4 JAR) Maintainability (+ org.hamcrest.core.jar) Build tools developers Extensibility (via Runners and Rules) Java 8 support Testing frameworks developers (Lambdas, Streams, Default Methods etc.) 3 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  4. JUnit 5 Architecture 5 th planet in Solar System! JUnit 5 = Platform + Jupiter + Vintage Source: http://junit.org/junit5/docs/current/user-guide/#dependency-diagram 4 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  5. JUnit 5 Architecture  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. 5 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  6. 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 support for JUnit 5 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 7 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  8. Demo JUnit Jupiter - Programming Model 8 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  9. 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: New JUnit Test Case wizard -> New JUnit Jupiter test 9 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  10. Add JUnit 5 library to the build path New JUnit Test Case wizard offers to add it Add library (JUnit) in while creating a new JUnit Jupiter test. Java Build Path dialog. Quick Fix (Ctrl+1) proposal on @Test. 10 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.jupiter.api.Test @org.junit.Test (No expected and timeout attributes) @BeforeClass @BeforeAll @AfterClass @AfterAll @Before @BeforeEach @After @AfterEach @Ignore @Disabled 11 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  12. Create a new JUnit Jupiter test method Create a JUnit Jupiter test method in Eclipse with the new template: test_jupiter 12 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  13. Assertions (org.junit.jupiter.api.Assertions class ) • Failure message comes at the end of arguments list. • Failure message can be retrieved lazily. • Grouped assertions to execute all assertions first and then report all failures together. • Exception testing to assert and evaluate a thrown exception. • Asserting that the given task completes before the given timeout. 13 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  14. Assumptions (org.junit.jupiter.api.Assumptions class ) 14 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  15. Eclipse Favorites JUnit Jupiter’s Assertions , Assumptions, DynamicContainer & DynamicTest classes are now added to Eclipse Favorites by default. Preferences -> Java -> Editor -> Content Assist -> Favorites 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. 15 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  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. 16 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. Example: TestingAStackDemo in JUnit 5 user guide. (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. 17 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  18. Test interfaces and default methods • Default test methods can be inherited by implementing test classes. • Enables multiple inheritance in tests classes. Example: StringTests in JUnit 5 user guide. 18 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  19. Tagging and Filtering • Tag test classes and test methods with @Tag . • Tags can later be used to filter test execution. Provide tags to be included in or excluded from a test run via Configure Tags dialog in its JUnit launch configuration. 19 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  20. Meta-annotations and composed annotations • JUnit Jupiter annotations can be used as meta-annotations . • Create custom composed annotation inheriting semantics of its meta-annotations. 20 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  21. Dynamic Tests • Dynamic tests are generated at runtime by a @TestFactory method. test_factory Create a @TestFactory method in Eclipse with the new template: • Dynamic container is composed of a display name and a list of dynamic nodes. • Dynamic test is composed of a display name and an Executable. There are no lifecycle callbacks for individual dynamic tests. 21 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  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. 22 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  23. Dependency Injection • Test constructors and methods are now permitted to have parameters enabling Dependency Injection. • ParameterResolver is the extension API to provide a parameter resolver which dynamically resolves a parameter at runtime. • A parameter resolver can be registered via @ExtendWith( … ) annotation. • JUnit Jupiter provides some built-in resolvers which are registered automatically: o TestInfo (resolved by TestInfoParameterResolver ) to access information about the currently executing test: 23 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  24. Dependency Injection o TestReporter (resolved by TestReporterParameterResolver ) to publish additional data from the currently executing test which can be seen in the Console view in Eclipse: • To support overloaded test methods, the Test Method Selection dialog in JUnit launch configuration now shows the method parameter types also: 24 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. • name attribute: to optionally specify a custom display name for each repetition. • RepetitionInfo : as test method parameter to get information about the current repetition. 25 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

  26. Parameterized Tests Run a test multiple times with different arguments by: • annotating the method with @ParameterizedTest • and declaring at least one source to provide the arguments. • name attribute: to optionally specify a custom display name for each invocation. • Test method may have additional parameters to be resolved by other ParameterResolver s at the end of the method's parameter list. 26 EclipseCon Europe 2017 | Embracing JUnit 5 with Eclipse | Noopur Gupta, IBM

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend