Course #:TP2398

Mastering Test-Driven Development using JUnit Training

This is a five-day, comprehensive hands-on test-driven development / JUnit / 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 students learn the best practices for writing great programs in Java, using test-driven development techniques. This comprehensive course also covers essential TDD topics and skills.

Students who attend Mastering Test-Driven Development using JUnit will leave the course armed with the skills they require to develop solid Java programs, using sound coding testing techniques and best coding practices. This course quickly introduces developers to the features of JUnit and educates them regarding JUnit’s strengths and weaknesses.

A complete understanding of TDD concepts, processes, and practices requires some in-depth hands-on experience.  During this class, students spend significant time working on a course project.  The project exercises are specifically oriented towards using TDD to implement a complex and multi-faceted web application that uses a database in its final form.  During the course project, the students:

  • Test basic Java functionality
  • Test web-functionality implemented in JEE
  • Use mocks for needed resources
  • Replace mocks and test database operations
  • Optionally, integrate the layers of the application using Spring and testing as they progress

This course includes coverage of many of the essential JUnit capabilities, and can be tailored to focus exactly on the areas that you are interested in.

Working within in a dynamic, learning environment, guided by our expert TDD team, attendees will:

  • Understand JUnit.
  • 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 test development.
  • 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.
  • Compile and execute programs using JUnit, jWebUnit, and DBUnit using the IDE of your choice.
  • How to extend testing with mock objects using EasyMock.
  • 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 4.x
  • EasyMock
  • PowerMock
  • jWebUnit
  • DBUnit


Experienced Java programmers


5 days

Outline of Mastering Test-Driven Development using JUnit Training

1. Introducing Test-Driven Development (TDD)

  • Test-Driven Development
    • Test, code, refactor, repeat
    • The ROI of TDD
    • Rationale
    • Advantages
    • Tools

2. JUnit

  • JUnit Overview
    • Purpose of Unit Testing
    • Good Unit Tests
    • Test Stages
    • Unit Testing Vs Integration Testing
  • Jumpstart: JUnit 4.x 
    • JUnit Overview
    • How JUnit Works
    • Launching Tests
    • Test Suites
    • JUnit Test Fixture
  • @Test Annotation
    • Test Execution Cycle
    • Checking for Exceptions
    • Using Timeouts
  • Hamcrest
    • About Hamcrest
    • The Hamcrest Matcher Framework
    • Hamcrest Matchers
  • Parameterized Tests 
    • Injecting the Parameters
    • Setting the Parameters
    • Test Execution Cycle
    • Observations
  • Theories
    • Writing Theory Enabled Tests
    • Defining DataPoints
    • Defining Theories
    • Observations
  • JUnit Best Practices
    • "Good" Tests
    • Bad Smells
    • White-Box Unit Testing
    • Black-Box Unit Testing
    • Automation and Coverage

3. Testing Tools

  • Web Testing: jWebUnit/HttpUnit
    • Presentation testing
    • Integration testing
    • jWebUnit
    • jWebUnit/HttpUnit
  • Mocking of Components
    • Why We use Test Dummies
    • Mock Objects
    • Working with Mock Objects
    • Using Mocks with the User Interface
    • Mock Object Strategies
  • Mock Objects and EasyMock
    • EasyMock Description and Features
    • EasyMock Object Lifecycle
    • Create/Expect Phase
    • Replay/Verify Phase
    • Mocking Complex Objects
    • EasyMock HOWTO
  • PowerMock
    • PowerMock Description and Features
    • PowerMock Object Lifecycle
    • Mocking a Static Method

4. Advanced Topics

  • State-based vs. Interaction-based Testing 
    • State-based vs. Interaction-based Testing
    • State-based Testing 
    • Interaction-based Testing 
    • Pros and Cons of Each
  • Improving Code Quality Through Refactoring
    • Refactoring Overview
    • Refactoring and Testing
    • Refactoring to Design Patterns
    • Naming conventions
  • Database Testing
    • Database Testing: DBUnit
    • Issues related to database testing
    • Persistence mechanisms
    • DBUnit

5. Appendix: Adding Testing to the Build Process

  • JUnit and Ant
  • The Ant JUnit Tag
  • Running JUnit Tests From Ant
  • Generating a JUnitReport
We regularly offer classes in these and other cities. Atlanta, Austin, Baltimore, Calgary, Chicago, Cleveland, Dallas, Denver, Detroit, Houston, Jacksonville, Miami, Montreal, New York City, Orlando, Ottawa, Philadelphia, Phoenix, Pittsburgh, Seattle, Toronto, Vancouver, Washington DC.