Good Unit Tests

Author:
Florin CoroČ™

Trainer:
Florin CoroČ™


Overview

By participating in this training you will understand what Good Unit Tests are and how you and your team can have real benefits from unit testing. Most of the teams fail in benefiting from unit testing, not because they are not motivated to write them and not because they do not believe in unit testing, but because they are not aware of what unit testing really means and because they do not master some key techniques in writing tests which last; tests which are maintainable, readable and trustworthy.

When unit testing is done incorrectly it can cause your schedule to slip, waste your time, lower your motivation, and lower your code quality. It is a double-edge sword, which many teams learn to master the hard way.

The greatest benefit of writing unit tests the right way is not a bug free code, nor full coverage in regression testing. The greatest benefit you will gain by writing good unit tests is the quality of your code design. It puts a very positive pressure on the design of your code making it inexpensive to change. You and your team will be pursued by good unit tests to discover and apply powerful object oriented design principles and practices. Therefore, the highest benefit you will gain is the decrease of the cost of change. Your code will stand the test of time.

There are studies showing that raising the overall code quality in a software project will increase productivity, efficiency and shorten schedules. Writing unit tests the right way is a powerful tool to improve quality.


Motivation

You should invest in writing good unit test because:

  • it reduces the cost of change
  • it reduces the accidental complexity of your product
  • improves the predictability of a change, no matter how large your system is
  • produces clean code that works
  • makes development faster
  • forces the developers to slow down and think

To master unit testing is not only about getting the knowledge. It is about developing skills. It is about getting the experience. The easier way to get your team there is to make it understand the concepts and techniques and to place it on the right path. Than it needs to be mentored and supported by someone who has walked the path before. This training covers the first part.


Learning Objectives


  • Achieve a correct understanding of what unit testing is
  • Learn how to obtain a healthy suite of unit tests, from which you get real benefits
  • Learn how to write unit tests that last and have a low maintainability cost
  • Learn how to benefit from the positive pressure the unit tests put on your production code driving it to a better code design
  • Learn techniques of refactoring the production code towards a testable design
  • Learn techniques of adding automated tests to legacy code

Target Audience

Any software architect or software developer would benefit greatly from this training.


Prerequisites

Object Oriented Programming basics (inheritance; encapsulation; polymorphism; interfaces; abstract classes; virtual methods; overriding; overloading).


Format and Agenda

The training is structured in two parts. First part focuses on explaining, exemplifying, and discussing the technical concepts to reach the targeted learning objectives. Each of the sections are listed below. The second part is practical and focuses on demonstrating and exercising the techniques presented in the first part. A more completed outline of the content can be provided as an addendum to this offer.

  • Part 1: Understanding the Key Concepts
    • Basics of Unit Testing
    • Testing & Isolation Frameworks
    • Understanding Mocks and Stubs
    • Core Techniques for Good Unit Tests
    • Good Unit Tests Ask for Quality Code
    • Maintaining the Unit Test Code
    • The Three Pillars of Good Unit Tests
    • Automated Test Types
  • Part 2: Demonstrating and Practicing
    • Demonstrating how to write good unit tests, by developing a small application
    • Workshop: assisted practice

The recommended format for delivering the entire course is in two consecutive days. This assures a balanced pace between explaining the material, having examples and discussions and practicing. There is also the possibility to shorten the duration and to tailor the content based on your needs.

Additionally, this class course training could be followed by workshops or coaching sessions, which focus more on practicing, and applying these concepts on a specific project or context. This would contribute to adopting the practices of good unit testing by project teams.


Offer

Please contact me for requesting an offer tailored to your needs.


Outline


Part 1: Understanding the Key Concepts

Section 1: Basics of Unit Testing

  • What is a GOOD Unit Test
  • What is an Integration Test
  • Why write Unit Tests
  • What to test
  • How many unit tests will we have

Section 2: Tools and Frameworks

  • Test Frameworks
  • Isolation Frameworks
  • Code Coverage Tools

Section 3: Core Techniques for GOOD Unit Tests

  • Isolation
  • Test Inhibiting Design to TOOD
  • Understanding Mocks vs Stubs
  • Test Doubles

Section 4: Good Unit Tests Ask for Quality Code

  • Why we want quality code
  • Getting to quality code by doing Good Unit Testing
  • Patterns and Principles emerging from the Good Unit Test positive pressure
  • Test Code Cycle
  • Code Coverage Pressure

Section 5: The Unit Test Code

  • Testing an Abstract Class
  • Good Practices for Writing Unit Tests
  • Unit Test Types
  • Test Class Inheritance Patterns
  • Organizing Unit Test Code

Section 6: The Three Pillars of GOOD Unit Tests

  • Readability
  • Maintainability
  • Trustworthiness

Section 7: Automated Test Types

  • Tests granularity
  • Types of Integration tests
  • Adding Automated Tests to Legacy Code

Part 2: Demonstrating and Practicing

Section 8: Code Demonstration

This will be a demonstration on how to write unit tests and production code in very small cycles, by implementing from the start a small application in very short functional iterations.

The sample will focus on showing the practices explained above and the benefits of unit testing on the code design.

Section 9: Assisted Practice

The participants continue the started implementation on their own. The trainer assists them.