Skip to main content

Instructor-led training

Java Testing with JUnit 5 Training in Merriam, Kansas

Private Java Enterprise Edition training for organizations from Hartmann Software Group, delivered onsite in Merriam, Kansas or live online.

What you'll learn

This course 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.
 
Testing with mocks is covered in detail, using Mockito. Mocking is a standard technique, and we’ll go beyond the basics to introduce more flexible options, as well as Mockito’s dependency injection facilities. We use the new MockitoExtension to integrate Mockito into JUnit tests.
 
We explore testing enterprise components in the persistence, service, and web layers, outlining the issues involved in each. In the persistence layer, we show how to set up and use an embedded database, and contrast this to using mocks or fakes as a standalone alternative. We examine the unique issues in database testing with regard to test repeatability and independence, using various techniques for auto-rollback of transactions.
 
In-container testing is introduced as a more meaningful approach to testing enterprise components, vs. standalone testing with mocks, and we examine this at each of the main layers in an enterprise application.
 
Best practices are emphasized and demonstrated throughout, and our goal is to make you “test infected,” so that your development effort is as much about good testing and writing testable code as it is about writing the business code itself.

Private Training for Teams

This course is offered as private, instructor-led training for organizations, onsite in Merriam, Kansas or live online. Dates, delivery format, and course content are arranged around your team's requirements.

This course is not currently scheduled as a public class for individual enrollment.

Request Group Training

Prerequisites

The student is expected to have a good working knowledge of Java and OO, including the use of interfaces, abstract classes, collections, factories, and generics. Experience with Java 8 lambda expressions is helpful, but not strictly required. A brief primer on the Java 8 features employed by JUnit is included in the course and covered if necessary.

Course Outline

Session 1: Unit Testing with JUnit 5
Overview
Introducing JUnit 5
JUnit 5 Library Components
Writing and Running Tests
Tests and Assertions
Test Methods
Assertions in Depth
Assertion Messages
Test Fixtures and Lifecycle
@BeforeEach, @AfterEach
@BeforeAll, @AfterAll
Test Lifecycle
 
Session 2: Writing and Running Tests
Java 8 Features Used in JUnit 5
Additional Testing Needs - Exceptions, Timeouts, Assertion Groups
Running Tests
IDE Support
maven support
JUnit Platform Console Launcher
Test Discovery and Selection
Test Configuration
Nested Tests
Advanced Capabilities
Extensions
Callbacks and Insertion Points
Conditional Test Execution
Parameterized Tests
JUnit 4 Migration
Best Practices
 
Session 3: Testing with Mocks
Overview and Mockito Introduction
Creating and Using Mocks
The Mockito Class and Mock Creation
Mock Creation with JUnit 5
Stubbing
Additional Capabilities
Argument Matchers
Partial Mocking with Spies
Dependency Injection with Mocks
 
Session 4: Testing Enterprise Components
Overview
Types of Testing
Standalone vs In-Container Testing
Testing the Persistence Layer
Testing Services
Testing Web Components

What makes testing with JUnit 5 and Mockito hard to master

Writing an assertion is easy. The harder skills are deciding what to test, isolating it, and keeping tests repeatable. The syllabus builds these in order.

  • Core mechanics first (Session 1). Test methods, assertions in depth, assertion messages, and the fixture callbacks @BeforeEach/@AfterEach and @BeforeAll/@AfterAll. A common misconception is that tests share state. The lifecycle topic is where you learn how instances and fixtures are scoped, and why order-dependent tests become fragile.
  • JUnit 5 is not JUnit 4 with new annotations (Session 2). The course covers extensions, callbacks and insertion points, conditional execution, parameterized tests, nested tests and JUnit 4 migration. The extension model replaces older runner and rule habits. The Java 8 features the library relies on (lambdas, for example in assertion groups and timeouts) get a primer.
  • Running tests is its own topic. IDE support, Maven, the JUnit Platform Console Launcher, and test discovery and selection matter because a test that passes in the IDE but is never picked up by the build gives false confidence.
  • Mocking (Session 3). Stubbing, argument matchers, spies for partial mocking, and dependency injection with mocks. The usual trap is over-mocking, which produces tests that restate the implementation instead of checking behavior.
  • Enterprise layers (Session 4). Standalone versus in-container testing across persistence, service and web components. Database tests raise repeatability and independence problems, which the course addresses with embedded databases and automatic transaction rollback.

Who it suits and what to take around it

The course is general level and runs two days. It assumes good working knowledge of Java and object-oriented design, including interfaces, abstract classes, collections, factories and generics. Lambda experience helps but is not required. It suits developers new to unit testing, and developers who know JUnit 3 or 4 and need to move to JUnit 5. Training managers can use it to align a team on one testing approach. The version named in the course material is Java SE 8, which is in Extended Support only, until December 2030. Organizations on newer Java releases can ask for private training tailored to the versions they use through a training proposal.

Session 4 tests persistence, service and web components. Teams building those layers may find it useful to learn the layers themselves first. Fast Track to EJB 3.2 (JEE 7 level) and JPA2 covers the persistence and component side. Developing Java EE Web Applications (JEE6/JEE7), plus JPA and REST covers the web side. Other options are listed in the Java Enterprise Edition course guide.

Illustrative scenarios

The scenarios below are illustrations of how the course material can be applied. They are not descriptions of specific organizations or of the course's lab exercises.

  • Migrating an existing suite. A team maintaining a large JUnit 4 test base might use the JUnit 4 migration topic, along with nested tests and parameterized tests, to restructure repetitive tests. They would move to the JUnit 5 extension model and adopt a consistent naming and fixture convention.
  • Testing a service with collaborators. A developer might use Mockito stubbing, argument matchers and the MockitoExtension to test a service class without its repository or remote client. A spy could cover a class that cannot be fully replaced, with dependency injection of mocks reducing setup code.
  • Making database tests repeatable. A team whose persistence tests fail intermittently because they leave data behind might compare an embedded database with mocks or fakes. They could then apply automatic rollback, so each test starts from a known state and does not depend on the others.

AI coding assistants and testing

AI coding assistants are good at drafting boilerplate: a test class skeleton, a set of assertions for an obvious method, or a parameterized test's data table. They are also useful for suggesting edge cases you had not listed.

They fail in ways specific to these topics:

  • Mixed JUnit generations. Generated code can combine JUnit 4 and JUnit 5 imports and annotations, or use runner and rule idioms that the extension model replaces. The tests may then compile but not run as intended.
  • Over-mocked tests. Assistants often mock everything, so the test passes while verifying nothing about real behavior. Misused argument matchers and misplaced spies are also common.
  • Weak database tests. Generated tests may ignore transaction rollback and leave data behind, which breaks test independence.
  • Shallow assertions. A test can run the code yet assert almost nothing.

To verify, run the tests through the build as well as the IDE, so you know they are discovered. Then deliberately break the code under test and confirm the test fails. Check that tests pass in any order and on repeated runs. Check the output against the project's Java and library versions, since the course material names Java SE 8.

Frequently asked questions

What level is this course, and who is it for?

It is a general-level, two-day course for developers who already know Java and object-oriented design. It suits those new to testing and those who know JUnit 3 or 4 and want to work with JUnit 5.

Do I need to know Java 8 lambda expressions?

Not strictly. Experience with them helps, and the course includes a short primer on the Java 8 features JUnit 5 uses, covered as needed.

What does the course cover beyond JUnit itself?

The syllabus includes Mockito (mock creation, stubbing, argument matchers, spies and dependency injection with mocks). It also covers standalone versus in-container testing and testing the persistence, service and web layers.

Can the course be delivered privately for our team?

Yes. HSG delivers private training for organizations, onsite at the client's location or live online.

Can the content be customized?

Private courses can be customized, including to the technology versions your organization uses. You can describe your needs through a training proposal request.

Training locations

Java Testing with JUnit 5 training across the U.S. and beyond.

We provide private Java Testing with JUnit 5 training for organizations, onsite at your location or live online, throughout the United States and internationally.

View all Java Testing with JUnit 5 training locations

Train your team with HSG

Private, instructor-led training customized for your organization.

  • Onsite or live online delivery
  • Customized curriculum
  • For a single employee or an entire team
  • Flexible scheduling
  • Experienced instructors
Request Group Training

Questions? Call us at 303.377.6176
or email info@hartmannsoftware.com

Ready to train your team?

Let's customize this training for your organization.

Tell us about your employees, your goals, and your preferred schedule. We'll prepare a training proposal covering scope, delivery format, and pricing.