Back to training

xUnit Test Craftsmanship for Developers

About

xUnit is the name given to the family of unit testing frameworks first popularized by JUnit. Most members of the family share a common architecture, core principles and feature set. While writing unit tests is “easy”, writing cost-effective unit tests that don’t slow you down and are easy to understand and maintain requires experience and discipline.

This interactive, hands on course allows you to discover what it takes to build high-quality, robust, repeatable and easy-to-read-and-write unit tests. Over two days, you will learn, try and gain experience with the key techniques that take most developers years to figure out. Even developers with many years experience writing unit tests say they learned a lot on this course.

Gerard Meszaros is an independent software development consultant with 25 years experience in software and a nearly two decades of experience applying agile methods.  His book xUnit Test Patterns – Refactoring Test Code was published in May 2007 by Addison Wesley Professional in the Martin Fowler Signature Series and won a Jolt Productivity Award in the Best Technical Book category.

Who should attend

  • The course is for developers. Some experience using JUnit, NUnit or similar xUnit framework. Even developers with many years experience writing unit tests say they learned a lot on this course.

    The students must have programming experience from programming Java, C# or similar. All programming exercises will be performed using Java or C#.

Why attend

Participants should leave the course with at least a basic understanding of:

What is the role of automated unit testing?

  • What is developer testing?
  • Why do developers need to test?
  • How to “think like a tester”
  • How to determine which tests to write?
  • Why should I automate tests?

How to automate tests with xUnit

  • Basic mechanics of test automation
  • What tests should I automate?
  • Proper use of assertions
  • Testing of exceptions
  • Ways to set up the test fixture and when to use which
  • Use of Test Doubles (stubs/mocks/fakes/dummies) to isolate the class being tested
  • Common problems and how to avoid them
  • Bad smells (symptoms) and what they mean

How to maximize the effectiveness of your tests

  • When to write the tests
  • How to verify the tests
  • How to make the tests maintainable and useful as documentation
  • How to make tests portable (run anywhere)
  • How to make tests repeatable and robust (provide consistent results even as the system evolves)

Structure

This is a two-day course consisting of 10 modules. Each module consists of a presentation of the theory and examples followed by an exercise where the students get to put the theories into practice. On average, about 50% of the time spent on each module is spent doing and debriefing the hands on exercises.

The modules are:

Introduction to Testing

  • Introduction to the basic concepts and terminology of software testing:
  • Unit vs Component vs. Functional Tests.
  • Black box vs. White Box tests
  • Acceptance Tests vs Regression Tests

Basics of xUnit

  • Introduction to the basic concepts and terminology of the JUnit (or equivalent) software testing framework.

Unit Testing Methodology

  • How to determine the minimal set of test conditions required to test a piece of software sufficiently.
  • When should tests be automated? How does this impact the development process?
  • Test Conditions, Test Cases & Test Scenarios
  • Equivalence Classes & Boundary Conditions

Testing Style

  • How do you ensure tests are understandable and easily found?
  • Economics of test automation; how automated testing can reduce cost.
  • How should test case classes and methods be named and organized?
  • Techniques for verifying the tests: Test Inspections, Testing the Tests, Code Coverage
  • Goals of unit testing: Tests as Specification, Tests as Documentation, Fully Automated Regression Testing

Introduction to Functional and Component Testing

  • How to define and automate functional tests.
  • Using use cases as a source of test conditions.
  • Using tests to document interface contracts

Verifying Expected Outcomes

  • How to use Assertions properly to make tests valuable as a specification.(intent revealing) while verifying that actual outcomes match expected outcomes without over-specifying the system behavior.
  • Verify expected outputs using Guard Assertions, Expected Objects & Custom Assertions (Patterns)

Setting up the Test Fixture

  • How to initialize the test fixture required to run a test using various fixture setup strategies. Common problems and how to solve them.
  • Test robustness and repeatability

Testing Indirect Inputs

  • Using stubs and real components to verify proper behavior for all inputs from used components
  • Testing handling of Exceptions thrown by used components (and how to force them to be thrown)

Testing Indirect Outputs

  • Using stubs and real components to verify expected outputs via used components

Design for Testability

  • Designing software so that it can be tested easily. Includes how to enable use of stubs. 

Prerequisites

At least 6 months experience programming in language of training

Most students will get significantly more out of this course if they already have prior experience in using an xUnit-based open-source testing framework.

Practical details

  • Included: welcome coffee, lunch and coffee breaks
  • Training language: English
  • The students are expected to bring a laptop with a development environment for Java or C# installedEach exercise and its suggested solution will be available as an Eclipse project and a Visual Studio 2015 solution.

  • Students will work in pairs to maximize learning and to ensure that no one gets “stuck”.

  • Participants will receive a certificate of attendance

Need a customized workshop? Contact us and we’ll adapt the content as required.