Junit 5 User Guide
Total Page:16
File Type:pdf, Size:1020Kb
JUnit 5 User Guide Stefan Bechtold, Sam Brannen, Johannes Link, Matthias Merdes, Marc Philipp, Christian Stein Version 5.1.1 Table of Contents 1. Overview . 1 1.1. What is JUnit 5? . 1 1.2. Supported Java Versions . 1 1.3. Getting Help . 1 2. Installation . 1 2.1. Dependency Metadata . 1 2.2. Dependency Diagram . 3 2.3. JUnit Jupiter Sample Projects. 4 3. Writing Tests . 4 3.1. Annotations . 4 3.2. Standard Test Class. 6 3.3. Display Names . 8 3.4. Assertions . 8 3.5. Assumptions. 13 3.6. Disabling Tests. 14 3.7. Conditional Test Execution. 15 3.8. Tagging and Filtering. 20 3.9. Test Instance Lifecycle . 21 3.10. Nested Tests . 22 3.11. Dependency Injection for Constructors and Methods. 24 3.12. Test Interfaces and Default Methods . 27 3.13. Repeated Tests. 32 3.14. Parameterized Tests . 35 3.15. Test Templates . 45 3.16. Dynamic Tests . 45 4. Running Tests . 49 4.1. IDE Support . 49 4.2. Build Support. 50 4.3. Console Launcher. 61 4.4. Using JUnit 4 to run the JUnit Platform . 65 4.5. Configuration Parameters . 67 4.6. Tag Expressions . 67 5. Extension Model . 68 5.1. Overview . 68 5.2. Registering Extensions . 68 5.3. Conditional Test Execution. 72 5.4. Test Instance Post-processing . 73 5.5. Parameter Resolution . 73 5.6. Test Lifecycle Callbacks. 73 5.7. Exception Handling . 76 5.8. Providing Invocation Contexts for Test Templates . 77 5.9. Keeping State in Extensions . 79 5.10. Supported Utilities in Extensions . 79 5.11. Relative Execution Order of User Code and Extensions . 80 6. Migrating from JUnit 4 . 82 6.1. Running JUnit 4 Tests on the JUnit Platform . 82 6.2. Migration Tips . 82 6.3. Limited JUnit 4 Rule Support . 83 7. Advanced Topics. 84 7.1. JUnit Platform Launcher API . 84 8. API Evolution. 86 8.1. API Version and Status . ..