Unit Testing in a Team Sparkhound Presents by Steve Schaneville

Slides:



Advertisements
Similar presentations
Test Automation: Coded UI Test
Advertisements

Apache Struts Technology
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
A Brief Introduction to Test- Driven Development Shawn M. Jones.
XUnit Test Patterns writing good unit tests Peter Wiles.
Unit Testing Tips and Tricks: Database Interaction Louis Thomas.
By John Boal  Continuous Integration [CI] ◦ Automating the build process ◦ Build the entire system each time any new.
© 2012 Autodesk Automated Testing with the AutoCAD ®.NET API Scott McFarlane Senior Software Engineer, Woolpert, Inc.
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
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Test Driven Development Arrange, Act, Assert… Awesome Jason Offutt Software Engineer Central Christian Church
Who are we?. What do we do? Fulfillment Optimization.
Sofia Bulgaria Summer School IST eXPERT: Best Practice on e-Project Development 30 June - 2 July 2003 eXtreme programming.
A Practical Guide To Unit Testing John E. Boal TestDrivenDeveloper.com.
Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans.
Using Mock Objects with Test Driven Development Justin Kohlhepp
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.
1 Legacy Code From Feathers, Ch 2 Steve Chenoweth, RHIT Right – Your basic Legacy, from Subaru, starting at $ 20,295, 24 city, 32 highway.
Refactoring & Testability. Testing in OOP programming No life in flexible methodologies and for refactoring- infected developers without SOME kind of.
 Wes McClure  
Roy Osherove Sela Group ISerializable.com (blog)
Software testing techniques Software testing techniques Software Testability Presentation on the seminar Kaunas University of Technology.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Testing Spring Applications Unit Testing.
(1) Test Driven Development Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
Test Driven Development Introduction Issued date: 8/29/2007 Author: Nguyen Phuc Hai.
Google C++ Testing Framework Part 2: Assertion. Concepts A test case contains one or many tests. ◦ You should group your tests into test cases that reflect.
Essay & exam workshop BTC Introductions Essays What is an essay? What does an essay have? – Structure – Content – A title/topic!
Beginning Software Craftsmanship Brendan Enrick Steve Smith
1 Punishment Through Continuous Delivery If it hurts, do it more often…
Automated Testing for Dynamics CRM
Benjamin Unit Testing & Test-Driven Development for Mere Mortals.
Unit testing of the Services Telerik Software Academy Web Services and Cloud.
Build Robust Web Apps in the Real WakeUpAndCode.com * aka ASP.NET 5 before RC1.
TDD Unit tests from a slightly different point of view Katie Dwyer.
Real world Windows Phone development
ASP.NET Unit Testing Unit Testing Web API SoftUni Team ASP.NET
Unit Testing - solid fundamentals
Structure of a web application
TESTING TEST DRIVEN DEVELOPMENT
Better Unit Tests through Design Patterns: Repository, Adapter, Mocks, and more… Benjamin
Getting Started on The Project Bank in Visual Studio
Mocking Tool for easier unit testing
Developer Testing Tricks
MVC Architecture, Symfony Framework for PHP Web Apps
Introduction to Unit Testing in JavaScript
Test Driven Development
Top 10 Mistakes in Unit Testing
Software Testing.
Magento Technical Guidelines Eugene Shakhsuvarov, Software Magento
Testing & Testing Tools
CO6025 Advanced Programming
Unit Testing & Test-Driven Development for Mere Mortals
Smoke and Mirrors Prototype
Unit Testing & Test-Driven Development for Mere Mortals
Introduction to the MVVM Pattern
History, Characteristics and Frameworks
CSE341: Programming Languages Section 1
Organize your code with MVC
Refactoring Legacy AngularJS
Sharing the good, the bad, the ugly & What can we do about it?
Organization Leadership Skill Area
Smoke and Mirrors Prototype
Unit Testing & Test-Driven Development for Mere Mortals
Designing For Testability
European conference.
Test-Driven Development
Building highly scalable enterprise systems (on Azure)
Refactoring.
Software Testing.
Presentation transcript:

Unit Testing in a Team Sparkhound Presents by Steve Schaneville August 6, 2016

References / Bibliography Clean Code – Robert Martin Art of Unit Testing (Second Edition) – Roy Osherove Dependency Injection in .NET – Mark Seemann Working Effectively in Legacy Code – Michael Feathers

Questions?

Why This Topic I (and a team of people much sharper than me) tried to bring unit testing into an established and sizable development shop on multiple occasions in the past, and we failed repeatedly... … and then we finally succeeded.

What Will We Wiscuss? Benefits of unit testing What makes a unit test a unit test? (differences between unit tests and other kinds of tests) Patterns and conventions When should I run my tests? What should I test, and how many tests should I write? Should I use code coverage? How do I train my team?

Benefits of Unit Testing Refactor code with impunity Get to rev 1 much faster - you never fire up the UI while coding the back end Ex: AMS3’s Patient Chart Sync Ex: Coachwell’s GetActionCenterDetailsCommand

What makes a unit test a unit test? Target only a single behavior Contain only a single ASSERT Have no external dependencies Require no environment configuration If you project builds, all tests will run and pass (seriously, no dependencies!) Run FAST 50ms is too long Typically <10ms Invokes a public method (no privates or protecteds!) Any test that does not meet this criteria is not a unit test

Patterns and Conventions Where should I put my test class? How should I name my test class? TargetName_Tests How should I name my test method? TargetMethod_WithSomeConditions_YieldsSomeResult How should my test method be organized? (Answer: 3A) Arrange, Act, Assert Method name: Act_Arrange_Assert (for sorting) Space between each section

Arrange Refactor common arrange blocks into reusable methods Arrange everything as “valid”, then back off Don’t use testing framework initialization methods Arrange database repositories, don’t arrange your DbContext It’s harder to reason about arranging the DbContext Unit tests are not testing production code if you arrange the DbContext

Act Typically_only_1_line_of_code();

Assert Only a single assert per test Hard-code your “expected” values Don’t be TOO specific (ex. error messages) Be careful not to test your implementation But DO test your integration Fluent Assertions Assert on lists, entire objects, etc. Excellent messages for failed assertions

What tests should I write? Cover behaviors, not code Think “possible paths through” the code in test Rule of thumb: one test per line of code (seriously?!)

When should I run my tests? During the gated build When I first open any project When I change any code Just before I check in Every time I blink

What code should my tests target? What is a “unit”? Logical piece of functionality… typically a class (and my classes only have 1 public method!) What should I not bother testing? Exceedingly simple code, such as simple data-only property getters and property setters Generated code Layers in which the value of testing offers little value (ex. the service layer may be pass-through only) The entire app from service layer up? (how new is our team at this?)

Should I track code coverage? Use code coverage as a guide to determine what pieces of code you’ve missed that may need tests Do not require the team to meet a certain level of code coverage

Train the Team Get buy-in Don’t require 100% Don’t require 50% Practice, and ramp up slowly Debate

How do I write testable code to begin with? Answer: Create seams What is a seam and how do I create them? Dependency Injection Constructor Injection Property Injection Method Injection Inheritance Sensing object

Fakes! What are fakes? Hand-rolled fakes (with demo) Faking Frameworks Stubs – substitute for a dependency in the target code Mocks – a stub that is used in an assertion in your test Hand-rolled fakes (with demo) Faking Frameworks FakeItEasy (with demo) Moq Tons of others

Unit Testing in Legacy Code Everything we’ve discussed today requires that the code base be built with testing in mind (read: Dependency Injection) Working Effectively in Legacy Code – Michael Feathers BRDNUG – I’ll be giving a user group talk on this topic