Unit Testing & Test-Driven Development for Mere Mortals

Slides:



Advertisements
Similar presentations
Software Testing with Visual Studio 2013 & Team Foundation Server 2013 Benjamin Day.
Advertisements

Real World Scrum with TFS2013 Benjamin Day. Brookline, MA Consultant, Coach, & Trainer Microsoft MVP for Visual Studio ALM Team Foundation Server, Software.
Real World Scrum with Team Foundation Server 2013 Benjamin
Design for Testability: Mocks, Stubs, Refactoring, and User Interfaces Benjamin Day benday.com |
Computer Engineering 203 R Smith Agile Development 1/ Agile Methods What are Agile Methods? – Extreme Programming is the best known example – SCRUM.
Pragmatic Application Building: Step by Step Jay Sissom Principal Systems Analyst Indiana University
Design Patterns for MVVM Unit Testing & Testability Benjamin Day.
Real world Windows Phone development Igor
Unit testing C# classes “If it isn’t tested it doesn’t work” Unit testing C# classes1.
By Bob Bunson  Simulation of software development project  Fictitious system from Concept to Code  Oriented around the.
From 3 weeks to 30 minutes – a journey through the ups and downs of test automation.
Design for Testability: Mocks, Stubs, Refactoring, and User Interfaces Benjamin Day.
10 Ways to Get Your Project Started Right Benjamin Day.
Presenter - Donn Felker.  Senior Consultant for Microsoft Gold Certified Partner- Statêra.  8 years of experience in developing and architecting enterprise.
@benday #vslive Better Unit Tests through Design Patterns: Repository, Adapter, Mocks, and more… Benjamin
@benday #vslive Automated Build, Test & Deploy with TFS, ASP.NET, and SQL Server Benjamin
Craig Berntson
MVC and MVP. References enter.html enter.html
Todd Snyder Development Team Lead Infragistics Experience Design Group.
Testing in Extreme Programming
Building an Offline Smart Client using Domain-Driven Design Principles Tim McCarthy.
Top 10 Ways to Go from Good to Great Scrum Master Benjamin Day.
Team Foundation Server 2012 Builds: Understand, Configure, and Customize Benjamin Day.
Group C# 023 Dark Deer Hotel. Born in Education: graduated from Oles Honchar Dnipropetrovsk National University, Physics, Electronics and Computer.
Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans.
TEST-1 6. Testing & Refactoring. TEST-2 How we create classes? We think about what a class must do We focus on its implementation We write fields We write.
Zero to Hero: Untested to Tested with Visual Studio Fakes Benjamin
Copyright © 2005 Charlie Poole. All rights reserved Test First User Interfaces XP2005 Sheffield University June 18, 2005.
Real World SQL Server Data Tools Benjamin
To Git or Not to Git for Enterprise Development Benjamin Edward Thomson
Dp-024 C# Dark Deer Hotel. Born in Education: graduated from Oles Honchar Dnipropetrovsk National University, Physics, Electronics and Computer.
Beginning Software Craftsmanship Brendan Enrick Steve Smith
Automated Testing for Dynamics CRM
Benjamin Day Get Good at DevOps: Feature Flag Deployments with ASP.NET, WebAPI, & JavaScript.
Benjamin Unit Testing & Test-Driven Development for Mere Mortals.
Benjamin Day Role-based Security Stinks: Better Authorization in ASP.NET.
Beyond Basic Unit Testing: Mocks, Stubs, User Interfaces, and Refactoring for Testability Benjamin Day
Ognjen Bajić Ana Roje Ivančić Ekobit Efficient Application Testing.
Benjamin Day Real World Scrum with TFS 2015 & VSTS.
DevOps with ASP.NET Core and Entity Framework Core
Real world Windows Phone development
(Complex) Problem domain Requirements Specification
Unit Testing - solid fundamentals
Test-driven development
Better Unit Tests through Design Patterns: Repository, Adapter, Mocks, and more… Benjamin
Unit testing your metro style apps built using XAML
Building Custom Workflows
Top 10 Mistakes in Unit Testing
Building Web Applications with Microsoft ASP
Unit Testing in a Team Sparkhound Presents by Steve Schaneville
Entity Framework Core for Enterprise Applications
CO6025 Advanced Programming
Unit Testing & Test-Driven Development for Mere Mortals
Unit testing C# classes
Get Good at DevOps: Feature Flag Deployments with ASP
CIS16 Application Development – Programming with Visual Basic
Zero to Hero: Untested to Tested with Visual Studio Fakes
Unit Testing & Test-Driven Development for Mere Mortals
Real World Scrum with TFS & VSTS / Azure DevOps
Your code is not just…your code
From Development to Production: Optimizing for Continuous Delivery
2/24/2019 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
Non-Useless Unit Testing for Entity Framework Core & ASP.NET Core
Entity Framework Core for Enterprise Applications
Implementing Security in ASP.NET Core: Claims, Patterns, and Policies
Developing and testing enterprise Java applications
From Development to Production: Optimizing for Continuous Delivery
Designing For Testability
Jamie Cool Program Manager Microsoft
Your code is not just…your code
Presentation transcript:

Unit Testing & Test-Driven Development for Mere Mortals Benjamin Day @benday

Benjamin Day Brookline, MA Consultant & Trainer Scrum, DevOps, Team Foundation Server, Software Architecture & Testing Microsoft MVP Pluralsight Author Scrum.org Trainer @benday

Pluralsight.com Online courses DevOps with TFS2017 Scrum Master Skills

Getting Started with Visual Studio Team Services (VSTS) Just published on May 1st!

On with the show.

Overview What is a unit test? What is unit testing? Why do I care? How do I justify it to my self/boss/team? Design for testability Design Patterns Demos

Unit tests = Small chunks of code that test other small chunks of code

Typical Unit Testing Flow You’re writing a feature You’re also writing tests Feature code = the “System Under Test” (aka. “SUT”) At least one unit test method per public method on the SUT Asserts

Demo: Calculator Unit Tests

Why use unit tests?

Typical Development Flow You write code It appears to work You check it in You send it to QA QA sends back bugs You fix (repeat)

Typical Refactoring Flow You refactor code You write some new code, too You check it in It appears to work You send it to QA They send bugs You fix bugs You deploy to production The world lights on fire

$$$

$1m for IT to support an application. That’s looking grim.

Technical Debt

Technical Debt Little bits of not-quite-done Low-quality code 8 million line methods Coding standards violations Classes with unclear names and intent Buggy & Brittle

Unit tests can help tackle technical debt

Unit tests can help tackle technical debt That’s looking grim.

Unit Tests Proof that the code you’re writing actually works Run-able by a computer Proof that the code you wrote a long time ago still works Automated regression tests Proof that bugs are still fixed

Awesome side effects of unit tests Focus on quality early Don’t rely on QA to tell you your code is broken Fewer low-value bugs coming back from QA NullReferenceException QA can focus on “exploratory testing” Better use of QA’s time Refactor with confidence Keep your code clean Clean code is easier to read % time reading code vs. % time writing code Clean code is easier to build on top of

How I structure a unit test Unit test class tests a class in the system under test {NameOfSystemUnderTestClass}Fixture.cs Has a property called SystemUnderTest Typeof {NameOfSystemUnderTestClass} [TestInitialize] method called OnTestInitialize() One or more [TestMethod] Arrange Act Assert

Unit Tests vs. Integration Tests

How would you test this?

What is Design For Testability? Build it so you can test it. How would you test this? Do you have to take the plane up for a spin?

Interfaces, Dependency Injection, & Mocks Code against interfaces Dependency Injection “Advertise” your dependencies on the constructor Dependencies are references to interfaces Use mock classes to provide fake data

Advertise Dependencies on Constructor Less Awesome Now With More Awesome

Hard to test usually also means hard to maintain.

Design Patterns will help you to create a more testable & maintainable application.

What’s a Design Pattern? Well-known and accepted solution to a common problem Avoid re-inventing the wheel

Design patterns in architecture.

Popularized in Software by this book…

Design Patterns for this talk Dependency Injection Flexibility Repository Data access details Adapter Keeps tedious, bug-prone code contained Strategy Encapsulates algorithms & business logic Model-View-Controller Isolates User Interface Implementation from the User Interface Logic Testable User Interfaces Model-View-ViewModel

Repository Pattern Hide the existence of databases and services Hide the existence of Entity Framework & ADO.NET Code against an interface Allows you to use mock data without an actual database Separate Unit Tests from Integration Tests

Adapter Pattern Isolate the details of turning one object into another object To / from Entity Framework entities To / from WebAPI message types To / from ASP.NET MVC ViewModels and Models

Model-View-Controller (MVC) Test user interfaces without having to run an actual user interface ASP.NET MVC WPF / XAML Model-View-ViewModel (MVVM)

Strategy Pattern Isolate and test algorithms Validation Business rules

Demos

Any last questions?

Thank you. www.benday.com | benday@benday.com