Test-Driven Development in Java

Contact Us for Dates
2 days practical workshop for up to 12 people.

Contact us for Onsite Price

Test-driven development is one of the key enablers for agile development, that allows us to develop stable and refactorable code, whose intent is clear and whose design can evolve incrementally. TDD allows us to capture and validate the rules governing the behaviour of our code.And? it?s also fun! There?s a bunch of interesting tools available to assist us in developing robust tests, in identifying which tests to write, to help us compose tests and to automatically run our tests.

Layout

The training course combines lectures with practical exercises that help the delegates to put what they have learned on the training course into practice.  The exercises specifically build on what has been recently taught and are built up as the training course progresses.

Training Course Objectives

  • Use the JUnit and mocking libraries to write tests
  • Run tests from an IDE and from Maven/Gradle build scripts
  • Apply patterns and practices for writing testable code
  • Extend the scope of tests into analysis, design and documentation
  • Use tests to communicate with the customer

Who it is for

This training course is aimed at Java developers and analysts, typically in the context of adopting agile development practices.

Training Course Prerequisites

  • Delegates should have some appreciation for the issues involved in building large-scale applications. Delegates should also have a development background.

Chapters

Chapter 1 Introduction

  • Why test-driven development?
  • Is TDD necessary?
  • TDD is about...
  • red/green/refactor

Chapter 2 Getting Started

  • Separating code from tests
  • Package structures
  • JUnit 4 basics
  • Assertions
  • JUnit setup/teardown
  • Exceptions

Chapter 3 Writing Tests

  • Base test classes
  • Matchers
  • Naming / Organization
  • Implementation strategies
  • Exploring APIs
  • Parameterized test runners

Chapter 4 Writing

  • Equals and value objects
  • Seams and sensing
  • Seam types
  • Inheritance
  • Singletons and Statics
  • Dependency injection

Chapter 5 Test doubles

  • Test double taxonomy
  • Stubs
  • Fakes
  • Mocks
  • Mocking Libraries such as Mockito and PowerMock
  • Setting Expectations and Verifying Interactions
  • Mocking Gotchas
  • Testing Legacy Code

Chapter 6 Understanding the Code through Tests

  • Showing the Call Hierarchy
  • Generating Documentation from Tests
  • Parsing the Test Source Code
  • Transcripts
  • Fluent Interfaces

Chapter 7 Organising Tests

  • Test Suites
  • Explicitly-built Test Suites
  • Implicitly-built Test Suites
  • Filtering and Sorting
  • Ordering

Chapter 8 TDD in Context

  • Relationship to Other Agile Practices
  • Closing Discussion

Chapter 9 More on fixtures

  • Making the Context Concrete
  • One-time Setup for Classes
  • One-time Setup for Suites
  • Fixtures and Superclasses
  • Object Mothers
  • Fixtures as Objects
  • Data-driven Fixtures
  • Using Databases
  • Testing Database Code

Chapter 10 Theories

  • Tests vs Theories
  • Triangulating Tests
  • Parameter Suppliers
  • Assumptions

Chapter 11 Tests as Specification

  • The Trouble with TDD
  • Behaviour Driven Design using Cucumber
  • Customer Acceptance Testing using Cucumber and Selenium