Course Code: xunitnet
Duration: 14 hours
Prerequisites:
  • An understanding of Dot Net basics
Overview:

Unit testing is a testing approach that tests individual units of source code by modifying its properties or triggering an event to confirm whether the outcome is as expected. xUnit is one of the most popular unit testing frameworks available for .NET.

The goal of this course is to design and write tests that target the domain model and other key areas of your code base, develop professional-quality test suites, safely automate your testing process, and integrate testing throughout the application life cycle using xUnit.net (C#).

Format of the Course

  • Interactive lecture and discussion
  • Lots of exercises and practice
  • Hands-on implementation in a live-lab environment
Course Outline:

Goal of unit testing

  • State of unit testing
  • Consequences of having a bad test suite
  • Using coverage metrics
  • Attributes of a successful test suite

Unit test Overview

  • Shared, private, and volatile dependencies
  • Classical and London schools of unit testing
  • The differences between unit, integration, and end-to-end tests

Anatomy of a unit test

  • Structure of a unit test
  • Unit test naming best practices
  • Working with parameterized tests
  • Working with fluent assertions

Four pillars of a good unit test

  • Defining an ideal test
  • Understanding the Test Pyramid
  • Using black-box and white-box testing

Mocks and test fragility

  • Mocks vs stubs
  • Observable behavior and implementation details
  • Mocks and test fragility

Styles of unit testing

  • Comparisons
  • Functional and hexagonal architectures
  • Output-based testing

Refactoring

  • Four types of code
  • Humble Object pattern
  • Writing valuable tests

Integration testing

  • Role of integration testing
  • Test Pyramid concept
  • Writing valuable integration tests

Mocking best practices

  • Maximizing the value of mocks
  • Replacing mocks with spies

Testing the database

  • Prerequisites for testing the database
  • Database testing best practices
  • Test data life cycle
  • Managing database transactions in tests

Unit testing anti-patterns

  • Unit testing private methods
  • Exposing private state to enable unit testing
  • Leaking domain knowledge to tests
  • Mocking concrete classes