Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unit Testing: Control Your Dependencies!

Jon Reid
September 18, 2014

Unit Testing: Control Your Dependencies!

How to turn dependencies around so you can write code that is testable. Includes an example of testing networking code.

Jon Reid

September 18, 2014
Tweet

Other Decks in Programming

Transcript

  1. Return Value Test Arrange: Set up object Act: Call method

    that returns a value Assert: Compare against expected value Test SUT call method value System Under Test
  2. State Test Arrange: Set up object Act: Call method Assert:

    Query object in some way Test SUT call method result query
  3. Dependency Injection • Extract and Override • Method Injection •

    Property Injection • Constructor Injection http://www.flickr.com/photos/8499561@N02/2755481069
  4. Dependency Injection • Extract and Override • Method Injection •

    Property Injection • Constructor Injection • Ambient Context http://www.flickr.com/photos/8499561@N02/2755481069
  5. Dependency Injection M A N N I N G Mark

    Seemann FOREWORD BY GLENN BLOCK in .NET
  6. Types of Fakes M A N N I N G

    the art of with examples in C# FOREWORDS BY Michael Feathers Robert C. Martin SECOND EDITION ROY OSHEROVE
  7. Let’s Write a Test (1): Does it call GET exactly

    once? 1. Arrange ! 2. Act
 3. Assert
  8. Let’s Make a Fake • Stub the method • Record

    number of calls • Fake return value • Capture arguments Fake Cook
  9. Dependency Injection • Extract and Override • Method Injection •

    Property Injection • Constructor Injection http://www.flickr.com/photos/8499561@N02/2755481069
  10. QualityCoding.org @qcoding • Working Effectively with Legacy Code by Michael

    Feathers • Dependency Injection in .NET by Mark Seemann • The Art of Unit Testing by Roy Osherove • Test-Driven iOS Development by Graham Lee Resources