Java Testing with JUnit 5

Java Testing with JUnit 5

  4.4 out of 5 - Read Testimonials
Course Length:
Delivery Methods:
Next Live Class:Apr 15-16, 2021 10AM-5PM ET
Course Topics
  • Understand new JUnit 5 library structure, role of each component, and how they interact
  • Configure IDE projects to run tests natively, and via Maven Surefire
  • Write cohesive and effective tests, and design classes for testability
  • Understand the full test lifecycle, and employ it to configure test fixtures
  • Run tests using all available mechanisms: IDE, Maven, JUnit Console Launcher, Launcher API
  • Use test discovery and filtering to define and run test plans, including conditional test execution
  • Employ naming conventions at every level - test name, classname, display name
  • Organize tests with assertion groups and nested tests
  • Use test interfaces to apply good OO principles to testing
  • Understand the new JUnit extension model, and how to write and use them
  • Understand JUnit 4 compatibility and migration
  • Use mock objects with Mockito to support isolated testing
  • Explore Mockito's facilities for dependency injection of mocks
  • Use argument matchers for more generalized testing with mocks
  • Implement partial mocking with spies
  • Understand the issues in testing enterprise components
  • Understand the two basic approaches: standalone testing with mocks, and in-container testing
  • Test database access components, using both fakes and an embedded database
  • Understand the additional issues involved in testing the service and web layers
  • Exercise best practices throughout the testing effort
Available Delivery Methods
Public Class
Public expert-led online training from the convenience of your home, office or anywhere with an internet connection. Guaranteed to run .
Private Class
Private classes are delivered for groups at your offices or a location of your choice.
Course Overview

This Java Testing with JUnit 5 training class introduces experienced Java developers to the fundamentals and best practices in unit testing. It uses the JUnit 5 and Mockito libraries, both of which are ubiquitous in the Java community. It is intended for both developers who are new to testing, as well as those who are already familiar with it, but want more experience with testing using JUnit 5.

Note that JUnit 5 is substantively different than JUnit 4. Although the core testing principles are the same, there are substantial implementation differences, important new features, and a brand new extension model. Developers with JUnit 3 and 4 experience will be well-served by the course.

All labs are done with the Eclipse IDE, and the lab instructions include detailed directions for setting up and using it. The standard application server used is TomEE, but it is available for other major app servers, including WildFly/JBoss AS and IBM WebSphere AS.

Course Outline
  1. Unit Testing with JUnit 5
    1. Overview
      1. Unit Testing and JUnit Overview
      2. New Features in JUnit 5
      3. JUnit 5 Library Components
      4. Naming Conventions and Organizing Tests
    2. Tests and Assertions
      1. Writing Test Methods
      2. Assertions
      3. Assertion Messages
    3. Test Fixtures and Test Lifecycle
      1. Creating and Using Text Fixtures
      2. Test Run Lifecycle: @BeforeEach and @AfterEach, @BeforeAll and @AfterAll
      3. Controlling Test Instances
  2. Writing and Running Tests (includes brief primer on Java 8 new features)
    1. Additional Testing Needs
      1. Testing for Exceptions
      2. Setting Timeouts
      3. Assertion Groups
    2. Running Test
      1. IDE Support: Eclipse, IntelliJ IDEA
      2. Maven Configuration
      3. JUnit Platform Console Launcher
      4. Launcher API
      5. Test Discovery and Selection
      6. Display Names
      7. Grouping and Filtering with Tags
      8. Configuration Parameters
      9. Nested Tests
    3. Advanced Capabilities
      1. Custom Composed Annotations
      2. Inheritance with Test Classes
      3. Extensions
      4. Conditional Test Execution
      5. Parameterized Tests
    4. JUnit 4 Migration
      1. The Do-Nothing Case
      2. Using a JUnit 4 Runner
      3. API Changes
      4. JUnit 4 Runners and Rules
      5. JUnit 4 Test Suites
    5. Best Practices
      1. Testing Void and Private Methods
      2. Test Cohesion and Assertion Scope
      3. Characteristics of Good Tests
      4. Writing Testable Code
      5. Testing Anti-Patterns
  3. Testing with Mocks
    1. Overview
      1. Mock Objects as Collaborators
      2. Mockito Overview
    2. Creating and Using Mocks
      1. Basic Steps in Mocking
      2. The Mockito Class
      3. Mock Creation with @Mock
      4. JUnit 5 MockitoExtension
      5. Stubbing
    3. Additional Capabilities
      1. Argument Matchers
      2. Partial Mocking with Spies
      3. Mocking the Unmockable
      4. Dependency Injection of Mocks
  4. Testing Enterprise Components
    1. Overview
      1. Unit Testing vs. Integration Testing
      2. Testing with Mocks vs. In-Container Testing
      3. Mocks vs. Fakes
    2. Testing the Persistence Layer
      1. Database Options: Installed, Embedded, Embedded-in-Memory
      2. Standalone vs. In-Container Testing
      3. Test Independence and Transaction Rollback
      4. In-Container Testing with Arquillian [Overview]
    3. Testing Services
      1. Similar Issues, Different Layer
      2. Working with External Resources
      3. The Argument for In-Container Testing
    4. Testing Web Components
      1. Interfacing with External Clients
      2. Difficulties in Standalone Testing with Mocks
      3. Manual vs. Automated Testing
      4. Automated Testing with Selenium [Overview]
Class Materials

Each student in our Live Online and our Onsite classes receives a comprehensive set of materials, including course notes and all the class examples.

Class Prerequisites

Experience in the following is required for this Java Fundamentals class:

  • Good working knowledge of Java and OO, including the use of interfaces, abstract classes, collections, factories, and generics.

Experience in the following would be useful for this Java Fundamentals class:

  • Experience with Java 8 lambda expressions is helpful, but not strictly required.
Register for a Live Class
  • See More Class Dates

Please select a class.
Request a Private Class
  • Private Class for your Team
  • Online or On-location
  • Customizable
  • Expert Instructors
Request Pricing