Unit Tests & TDD in .Net an introduction
Agenda
  • Introduction
  • Unit Testing and development principles
  • TDD and DDD, an example using .Net
  • Discussion points
Agenda
  • Introduction
  • Unit Testing and development principles
  • TDD and DDD, an example using .Net
  • Discussion points
Introduction - conventions
  • SUT – a system under testing
  • A test project corresponds to a project to test, similarly, a test class tests a production code class.
  • Class names, SUT’s class name + Tests
  • Test doubles mocks
  • Method names, MethodName + Condition + Expectation
  • Inside a unit test, we apply the Arrange-Act-Assert pattern
 
Unit Testing and Development Principles

SOLID (Do you remember what that stands for?) and Unit Testing

  • At unit tests, each one of them targets a single behavior in SUT. These behaviors combined lead to an SRP.
  • Unit tests help to protect classes from changes that can break them from working, as tests should keep passing, so, OCP works hand in hand with unit tests to protect code.
  • There is no direct effect on LSP from unit tests. Similar case with ISP.
  • Shouldn’t interfaces a class depends on be slim so we can add them as required? No direct relation between unit tests and ISP.
  • DIP, in this case, there is a tight relationship with unit tests as this allows us to implement unit tests so we can mock the SUT as both tests and classes depend on interfaces we can inject.
 
TDD Sample – Web API TDD
  • An appointment booking website, barber shop appointments
  • Requirements are documented as stories; we’ll look at one story here:
  • Services Selection
  • As a customer, I want to have access to a list of available services and their cost
 
Overview: Unit Tests and TDD (Test-driven Development) in .Net an Introduction