Test Driven Development (TDD) and Unit Testing Essentials | TDD, JUnit5, Refactoring, Mocking, Best Practices

Jumpstart Your Test-Driven Development Programming Skills using JUnit and various Open-Source Testing Frameworks

TT3503

Introductory and Beyond

3 Days

Course Overview

Test Driven Development (TDD) and Unit Testing Essentials is a three-day, comprehensive hands-on test-driven development / JUnit 5 / TDD training course geared for developers who need to get up and running with essential Test-driven development programming skills using JUnit and various open-source testing frameworks. Throughout the course you'll learn, explore and gain practical experience working with best practices for writing great programs in Java, using test-driven development techniques. This course quickly introduces you to the core features and benefits of JUnit. You'll leave this course armed with the skills required to leverage solid test driven development and unit testing techniques, using the latest industry techniques and best practices.

This hands-on course combines engaging expert lessons, demos and group discussions with real-world, skills-focused machine-based labs and exercises. Throughout the course, you’ll work on a project with labs specifically oriented towards using TDD to implement a complex and multi-faceted web application that uses a database in its final form. Working in a hands-on learning environment, guided by our expert team, you will:

  • Learn about and work with JUnit.
  • Understand and use the JUnit Test Runner interface.
  • Use JUnit to drive the implementation of Java code.
  • Best practices and patterns for test development.
  • 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.
  • Compile and execute programs using JUnit and DBUnit
  • 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.

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 Objectives

This hands-on course combines engaging expert lessons, demos and group discussions with real-world, skills-focused machine-based labs and exercises. Throughout the course, you’ll work on a project with labs specifically oriented towards using TDD to implement a complex and multi-faceted web application that uses a database in its final form. Working in a hands-on learning environment, guided by our expert team, you will:

  • Learn about and work with JUnit.
  • Understand and use the JUnit Test Runner interface.
  • Use JUnit to drive the implementation of Java code.
  • Best practices and patterns for test development.
  • 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.
  • Compile and execute programs using JUnit and DBUnit
  • 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.

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.

Follow On Courses:  Our TDD and programming tracks include a wide variety of follow-on courses and learning paths for leveraging Java for next-level development, testing, security and more. Please see our Java Developer Training Suite & Learning Paths or Testing, TDD, Test Automation, Unit Testing & Web Testing Tools (Selenium, Gherkin, Cucumber) Suite of courses, or inquire for recommendations based on your specific role and goals.

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: Introducing Test-driven Development

Lesson: Test-Driven Development

  • Rationale for TDD
  • The process of TDD
  • Advantages to TDD
  • Side-effects of TDD
  • Tools to support TDD
  • Tutorial: Setup IntelliJ for Using Maven

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
  • Test Result Verification (Assertions)
  • Manage fixtures using @BeforeEach, @AfterEach, @BeforeAll and @AfterAll annotations
  • Maven setup using Surefire plugin
  • Lab: Demo JUnit
  • Lab: Build JUnit Case Study
  • Lab: Jumpstart JUnit

Lesson: Annotations

  • Use @DisplayName to specify a custom name for the test
  • Check for exceptions thrown by test
  • Use @Disabled to prevent a test class or method from running
  • Use timeouts to fail test that take longer than required
  • Test Execution Order
  • 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
  • Define different sources for test data (@ValueSource, @CsvSource, @CsvFileSource,@EnumSource, @MethodSource, @ArgumentSource)
  • Lab: Working with Parameterized Tests

Lesson: Advanced Features

  • JUnit 4 vs JUnit 5
  • Nested Unit Tests
  • Repeated Tests
  • JUnit Extensions
  • ExecutionConditions
  • 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: Mocking

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
  • JUnit 5 and Mockito Dependency Injection
  • Stubs Using ArgumentMatchers
  • Verifying Behavior in Mockito
  • Partial Mock Objects
  • The Spy annotation
  • Lab: Mock Object and Mockito

Lesson: PowerMock

  • PowerMock Description and Features
  • Using PowerMockito
  • @PrepareForTest
  • Mocking a final class or final method
  • Mocking a Static Method

Session: Advanced Topics

Lesson: State-based vs. Interaction-based Testing

  • State-based Testing
  • Interaction-based Testing
  • Mock Objects Support Each Approach
  • Three Areas to Check in a Test
  • Lab: Interaction-based Testing

Lesson: Improving Code Quality Through Refactoring

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

Lesson: Database Testing: DbUnit

  • Setting up DbUnit
  • Defining a Dataset File in XML, CSV or Excel
  • Writing a DbUnit Test Class
  • Assert the results
  • Use the FailureHandler and ValueComparer
  • Using Date and Time in test sets
  • Export a data set
  • Lab: Introduction to DbUnit
  • Lab: DbUnit Assertions
  • Lab: Selenium and DbUnit

Course Materials

Student Materials: Each student will receive a Student Guide with course notes, code samples, software tutorials, diagrams and related reference materials and links (as applicable). Our courses also include step by step hands-on lab instructions and and solutions, clearly illustrated for users to complete hands-on work in class, and to revisit to review or refresh skills at any time. Students will also receive the project files (or code, if applicable) and solutions required for the hands-on work.

Classroom Setup Made Simple:  Our dedicated tech team will work with you to ensure your classroom and lab environment is setup, tested and ready to go well in advance of the course delivery date, ensuring a smooth start to class and seamless hands-on experience for your students. We offer several flexible student machine setup options including guided manual set up for simple installation directly on student machines, or cloud based / remote hosted lab solutions where students can log in to a complete separate lab environment minus any installations, or we can supply complete turn-key, pre-loaded equipment to bring ready-to-go student machines to your facility.  Please inquire for details, options and pricing.

Trivera's EveryCourse Extras = High-Value & Long-Term Learning Support! All Open Enrollment courses include our unique EveryCourse Extras package (Post-Course Resource Site access, Review Labs, Live Instructor Follow-on Support, 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
Test Driven Development (TDD) and Unit Testing Essentials | TDD, JUnit5, Refactoring, Mocking, Best Practices 3 Days Feb 9 to Feb 11 10:00 AM to 06:00 PM EST $1,995.00 Enroll
Test Driven Development (TDD) and Unit Testing Essentials | TDD, JUnit5, Refactoring, Mocking, Best Practices 3 Days Apr 6 to Apr 8 10:00 AM to 06:00 PM EST $1,995.00 Enroll
Test Driven Development (TDD) and Unit Testing Essentials | TDD, JUnit5, Refactoring, Mocking, Best Practices 3 Days Jun 8 to Jun 10 10:00 AM to 06:00 PM EST $1,995.00 Enroll
Test Driven Development (TDD) and Unit Testing Essentials | TDD, JUnit5, Refactoring, Mocking, Best Practices 3 Days Aug 3 to Aug 5 10:00 AM to 06:00 PM EST $1,995.00 Enroll
Test Driven Development (TDD) and Unit Testing Essentials | TDD, JUnit5, Refactoring, Mocking, Best Practices 3 Days Oct 5 to Oct 7 10:00 AM to 06:00 PM EST $1,995.00 Enroll

Year-End Savings!
Register today to receive *50% off all 2021 Public Classes*!  Check out our Current Offers for Individuals, Teams and Organizations to Learn for Less!

See our latest Offers and Promotions

Learn. Explore. Advance!

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