Unit Testing Essentials using JUnit 5 and Mockito (with Best Practices)

Explore Unit Testing, JUnit, Best Practices, Testing Apps with Native IDE Support, Debugging, Using Mockito & More

TT3526

Intermediate

3 Days

Course Overview

JUnit 5 and EasyMock make it possible to write higher-quality Java code. These powerful tools are designed to support robust, predictable and automated testing development in the Java enterprise application arena.

Unit Testing Essentials using JUnit 5 and Mockito is a three-day, hands-on unit testing course geared for experienced developers who need to get up and running with essential unit testing skills using JUnit, Mockito, and other tools. Students will leave the course armed with the skills required to leverage solid unit testing practices using the latest industry techniques and best practices. This course quickly introduces developers to the features of JUnit and educates them regarding JUnit’s strengths and weaknesses.

Working in a hands-on learning environment, guided by our expert team, attendees will learn to:

  • Understand what unit testing is and what it is not intended to cover
  • Understand JUnit 5.
  • Understand and use the JUnit Test Runner interface.
  • Use JUnit to drive the implementation of Java code.
  • Test applications using native IDE support.
  • Best practices and patterns for unit testing.
  • Understand JUnit’s strengths and weaknesses
  • Understand the role of debugging when done in conjunction with tests.
  • Understand not only the fundamentals of the TDD using Java, but also its importance, uses, strengths and weaknesses.
  • Understand how JUnit affects your perspective on development and increases your focus on a task.
  • Learn good JUnit coding style.
  • Create well-structured JUnit programs.
  • Understand how JUnit testing can be used for either state-based or interaction-based testing.
  • How to extend testing with mock objects using Mockito.
  • Look at refactoring techniques available to make code as reusable/robust as possible.
  • Discuss various testing techniques.
  • The following JUnit-based testing frameworks are examined: JUnit 5; Mockito; PowerMock

Ways To Learn with Flexible Hours & EveryCourse Extras!

  • Attend a Class! For your convenience, this course is available on our online-live Public Schedule in full day format, or flexible hours half-day Mini-Camp short course sessions in AM or PM hours. Please see the current scheduled dates listed below.  Please ask if you don't see a date you'd prefer. Be also be sure to check out our current Special Offers for extra savings.
  • Team Training! We're also happy to deliver this as a private event for your team or organization, tailored to suit your needs.
  • Trivera's Every-Course Extras bring High-Value & Long Term Learning Support! All courses also include our unique EveryCourse Extras package (Post-Course Resource Site access with Review Labs & Live Instructor Follow-on Support, access to QuickSkills recorded High-Value lessons, Free *Live* Course Refresh Re-Takes, early access to Special Offers, Free Courses & more). Please inquire for details.

Course Objectives

This skills-centric course is about 50% hands-on lab and 50% lecture, designed to train attendees in core unit testing skills, coupling the most current, effective techniques with the soundest industry practices. Working in a hands-on learning environment, guided by our expert team, attendees will learn to:

  • Understand what unit testing is and what it is not intended to cover
  • Understand JUnit 5.
  • Understand and use the JUnit Test Runner interface.
  • Use JUnit to drive the implementation of Java code.
  • Test applications using native IDE support.
  • Best practices and patterns for unit testing.
  • Understand JUnit’s strengths and weaknesses
  • Understand the role of debugging when done in conjunction with tests.
  • Understand not only the fundamentals of the TDD using Java, but also its importance, uses, strengths and weaknesses.
  • Understand how JUnit affects your perspective on development and increases your focus on a task.
  • Learn good JUnit coding style.
  • Create well-structured JUnit programs.
  • Understand how JUnit testing can be used for either state-based or interaction-based testing.
  • How to extend testing with mock objects using Mockito.
  • Look at refactoring techniques available to make code as reusable/robust as possible.
  • Discuss various testing techniques.

The following JUnit-based testing frameworks are examined:

  • JUnit 5
  • Mockito
  • PowerMock

Need different skills or topics?  If your team requires different topics or tools, additional skills or custom approach, this course may be further adjusted to accommodate.  We offer additional unit testing, TDD, BDD, programming, testing tools, test automation, QA, services, security and other related topics that may be blended with this course for a track that best suits your needs. Our team will collaborate with you to understand your needs and will target the course to focus on your specific learning objectives and goals.

Course Prerequisites

This programming course is for experienced Java developers.

Please see the Related Courses tab for specific Pre-Requisite courses, Related Courses that offer similar skills or topics, and next-step Learning Path recommendations.

Course Agenda

Please note that this list of topics is based on our standard course offering, evolved from typical industry uses and trends. We’ll work with you to tune this course and level of coverage to target the skills you need most.

Session: Unit Testing using JUnit

Lesson: Unit Testing Fundamentals

  • Purpose of Unit Testing
  • Good Unit Tests
  • Test Stages
  • Unit Testing Vs Integration Testing
  • Understanding Unit Testing Frameworks

Lesson: Jumpstart: JUnit 5.x

  • Understand and work with the features of JUnit
  • Write unit tests using @Test annotation
  • Use @DisplayName to specify a custom name for the test
  • Manage fixtures using @BeforeEach, @AfterEach, @BeforeAll and @AfterAll annotations
  • Launch tests using @ExtendWith (@RunWith – JUnit 4+) annotation
  • Build test suites using @SelectPackages or @SelectClasses
  • Use @Disabled to prevent a test class or method from running
  • Lab: Demo JUnit
  • Lab: Build JUnit Case Study
  • Lab: Jumpstart JUnit
  • Lab: Reapplying JUnit

Lesson: Annotations

  • Describe the test execution cycle
  • Check for exceptions thrown by test
  • Use timeouts to fail test that take longer than required
  • Lab: Working with @Test Annotation

Lesson: Hamcrest

  • Learn the notation of assertThat
  • Know the objective of Hamcrest library
  • Use Hamcrest's logical and object matchers
  • Use Hamcrest's number and collection matchers
  • Lab: Working with Hamcrest

Lesson: Parameterized Tests

  • The @ParameterizedTest annotation
  • A parameterized test to test code under several conditions
  • Generic tests to support parameterized testing
  • Lab: Working with Parameterized Tests

Lesson: Advanced Features

  • Nested Unit Tests
  • Repeated Tests
  • JUnit Extensions
  • Conditions
  • Lambda Support
  • Grouped Assertions
  • Lab: Working with  Advanced Features

Lesson: JUnit Best Practices

  • "Good" Tests
  • Bad Smell
  • White-Box Unit Testing
  • Black-Box Unit Testing
  • Automation and Coverage

Session: Advanced Topics

Lesson: Mocking of Components

  • Why We use Test Dummies
  • Mock Objects
  • Working with Mock Objects
  • Using Mocks with the User Interface
  • Mock Object Strategies

Lesson: Mock Objects and Mockito

  • Mockito Description and Features
  • Mockito Object Lifecycle
  • Create/Expect Phase
  • Replay/Verify Phase
  • Mocking Complex Objects
  • Lab: Mock Objects and Mockito
  • Lab: Injection

Lesson: Improving Code Quality Through Refactoring

  • Refactoring Overview
  • Refactoring and Testing
  • Refactoring to Design Patterns
  • Naming conventions
  • Lab: Refactoring
  • Lab: Best Practices - Refactoring Tests

Session: Appendix

Lesson: Adding Testing to the Build Process

  • JUnit and Ant
  • The Ant JUnit Tag
  • Running JUnit Tests from Ant
  • Generating a JUnitReport

Course Materials

Student Materials: Each participant will receive a Student Guide with course notes, code samples, software tutorials, step-by-step written lab instructions, diagrams and related reference materials and resource links. Students will also receive the project files (or code, if applicable) and solutions required for the hands-on work.

Hands-On Setup Made Simple! Our dedicated tech team will work with you to ensure our ‘easy-access’ cloud-based course environment is accessible, fully-tested and verified as ready to go well in advance of the course start date, ensuring a smooth start to class and effective learning experience for all participants. Please inquire for details and options.

Ways To Learn with Flexible Hours & EveryCourse Extras!

  • Attend a Class! For your convenience, this course is available on our online-live Public Schedule in full day format, or flexible hours half-day Mini-Camp short course sessions in AM or PM hours. Please see the current scheduled dates listed below.  Please ask if you don't see a date you'd prefer. Be also be sure to check out our current Special Offers for extra savings.
  • Team Training! We're also happy to deliver this as a private event for your team or organization, tailored to suit your needs.
  • Trivera's Every-Course Extras bring High-Value & Long Term Learning Support! All courses also include our unique EveryCourse Extras package (Post-Course Resource Site access with Review Labs & Live Instructor Follow-on Support, access to QuickSkills recorded High-Value lessons, Free *Live* Course Refresh Re-Takes, early access to Special Offers, Free Courses & more). Please inquire for details.

Raise the bar for advancing technology skills

Attend a Class!

Live scheduled classes are listed below or browse our full course catalog anytime

Special Offers

We regulary offer discounts for individuals, groups and corporate teams. Contact us

Custom Team Training

Check out custom training solutions planned around your unique needs and skills.

EveryCourse Extras

Exclusive materials, ongoing support and a free live course refresh with every class.

Attend a Course

Please see the current upcoming available open enrollment course dates posted below. Please feel free to Register Online below, or call 844-475-4559 toll free to connect with our Registrar for assistance. If you need additional date options, please contact us for scheduling.

Course Title Days Date Time Price
Unit Testing Essentials using JUnit 5 and Mockito (with Best Practices) 3 Days Jun 21 to Jun 25 09:00 AM to 01:00 PM EST $2,195.00 Register
Unit Testing Essentials using JUnit 5 and Mockito (with Best Practices) 3 Days Jul 12 to Jul 16 02:00 PM to 06:00 PM EST $2,195.00 Register
Unit Testing Essentials using JUnit 5 and Mockito (with Best Practices) 3 Days Jul 20 to Jul 22 10:00 AM to 06:00 PM EST $2,195.00 Register
Unit Testing Essentials using JUnit 5 and Mockito (with Best Practices) 3 Days Aug 16 to Aug 20 09:00 AM to 01:00 PM EST $2,195.00 Register
Unit Testing Essentials using JUnit 5 and Mockito (with Best Practices) 3 Days Aug 23 to Aug 27 02:00 PM to 06:00 PM EST $2,195.00 Register

See Our Special Offers and Promotions
Trivera offers exclusive promotional offers here at our site that change regularly. Check back often and don’t miss these limited opportunities to learn for less.

See our latest offers and promotions

Learn. Explore. Advance!

Trivera EveryCourse Extras
Extend your training investment! Recorded sessions, free re-sits and after course support included with Every Course
Trivera MiniCamps
Gain the skills you need with less time in the classroom with our short course, live-online hands-on events
Trivera QuickSkills: Free Courses and Webinars
Training on us! Keep your skills current with free live events, courses & webinars
Trivera AfterCourse: Coaching and Support
Expert level after-training support to help organizations put new training skills into practice on the job

The voices of our customers speak volumes

Special Offers
Limited Offer for most courses.

SAVE 50%

Learn More