Unit Testing With JUnit 5
1 Day Workshop
This course is designed for testers and software developers who want to learn how to test software at a detailed level using JUnit 5 and JUnit Jupiter. The process taught in this course is specifically oriented to JUnit 5, and is reinforced by a series of hands-on exercises that allow you to build unit tests incrementally as the workshop progresses.
This course bridges the gap between solid unit test design and unit test automation. The course covers both functional and structural testing, with numerous examples and templates.
You will learn the terminology, process, and challenges of unit testing in the real world.
As a result of attending this seminar, you should have a good working knowledge of unit testing with JUnit 5, JUnit Jupiter, and what it takes to design and conduct an effective unit test with JUnit 5.
Currently, this course is available only in in-house presentations. E-learning will be available soon. Contact Us for booking information.
Who Should Attend
- Software developers
- Technical test analysts
Pre-Requisites
Working knowledge of:
- Eclipse IDE
- Maven
- Gradle (optional)
- Git
Return on Investment
- Learn how to find software defects early in the development lifecycle before they become more costly and risky to fix.
- Understand how to design a unit test.
- Learn how JUnit5 and related tools can help you perform unit testing more effectively.
- Get developers involved in testing.
- Advance your career by reinforcing your testing and test tool expertise.
Topics
Module 1 – Introduction to Unit Testing (15 mins.)
- What is Testing?
- The Economics of Testing – The 1:10:100 Rule
- When Should Testing be Performed?
- Testing and Risk
- Test-driven Development (TDD)
- What is Refactoring?
- Goals, Risks and Benefits of TDD
- What to Test with Unit Tests and What Not to Test with Unit Tests
- Key Testing Concepts
Module 2 – Unit Testing Prerequisites and Terminology (1 hour)
- Test Levels – Unit, Integration, System and User Acceptance Testing
- The “V” Model of Development and Testing
- The Process Workbench Model
- Defects
- Requirements
- Verification and Validation
- Functional (Black box) testing
- Structural (White box) testing
- Independent Testing
- Developer Testing
- What Unit Testing Should Cover
- What Unit Testing Should Include
- Unit Test Approach
- Unit Test Techniques
- Unit Test Tools
- Unit Test Responsibilities
- Unit Testing Challenges in Specific Contexts
- GUI
- Legacy
- Web-based
Module 3 - Intro to JUnit5 and JUnit Jupiter (45 mins.)
- What Is Junit5 And What Makes It So Powerful?
- JUnit5 Architecture
- High-level Overview
- JUnit 5 Architecture in a Picture
- JUnit Platform
- What is JUnit Jupiter?
- JUnit Vintage
- Running Tests With JUnit Platform
- JUnit5 APIs
- Discovering Tests
- Running Tests
- Test Plans and Specifications
- APIs for Running Tests
- The Launcher
- The Major Goal of Test Execution
- JUnit5 Service Provider Interface (SPI)
- Test Engine
- Using Third-Party Test Libraries
- Basic Structure of Unit Tests in JUnit 5 and JUnit Jupiter
- Test Case/Tests
- Test Suites
- Annotations
- Assertions
- Throwing Exceptions
- Assumptions
- Set Up
- Tear Down
- Mocks and Stubs
- Guidelines for Writing Unit Tests
- An Example
Module 4 – Writing and Running Tests (1.5 hrs.)
- The Unit Test Lifecycle
- Setup
- Exercise
- Verify
- Teardown
- Example
- Annotations
- Assertions
- Viewing Test Results
- Assumptions
- Example
- Assertions vs. Assumptions
- Core Annotations
- Example
- Exercise - Write and Run a Basic Test In JUnit 5
- Disabling and Ignoring Tests
- Exercise – Disable Tests
- Nested Tests
- Exercise – Organize Tests by Nesting Them
- Looking At A Sample Application
- Which Things Would Be Good To Test?
- How To Design Meaningful Tests?
- Equivalence Classes
- Boundary Cases
- Decision Tables
- Specification-Based Cases
- Requirements
- User Stories
- Error Forcing
- Structural Test Coverage Measures – Statement, Branch, Condition, Multi-Condition And Path
- Exercise - Run A Fleshed Out Test In Eclipse
- Measuring Code Coverage with JCov and JCoCo
Module 5 – Going Deeper With JUnit5 (2.5 hrs.)
- The JUnit 5 Extension Model
- Extension Points
- The JUnit Test Lifecycle Callbacks
- Creating an Extension
- Example
- Automatic Extension Registration
- Enabling Automatic Extension Detection
- Example
- Extension Inheritance
- Activating an Extension
- Parameter Injection
- The “Happy Path”
- ParameterResolver Interface
- Creating a ParameterResolver Implementation
- Using a ParameterResolver Implementation
- Example
- Exercise
- Parameterized Tests
- Parameter Injection Using…
- @ValueSource
- @EnumSource
- Other Sources
- Optional Mode Parameters
- @MethodSource
- @CsvSource
- Example
- Exercise – Adding Parameters to a Test
- Parameter Injection Using…
- Conditional Test Execution
- How To Add Conditional Statements
- Deactivating Execution Conditions
- Example
- Exercise – Adding Conditions to a Test
- Repeated Tests
- Example
- Custom Display Names
- Example
- Lifecycle Support for @RepeatedTest
- Example
- Exercise – Add Repeats and Display Names to a Test
- Dynamic Tests
- What is a Dynamic Test?
- The @TestFactory
- The Dynamic Test Library
- Examples
- Exercise – Running a Dynamic Test
- Tagging and Filtering
- Meta-Annotations and Composed Annotations
- Example
- Exercise
Module 6 – Integration Considerations of JUnit5 (1 hr.)
- Mockito
- Selenium
- Cucumber
- Docker
- Exercise (if time permits)
Deliverables
• Course notebook with slides, worksheets, checklists, complete examples and supporting text
• You will have the basic information needed to plan and execute a unit test using JUnit 5