Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
A Gentle Introduction to Unit Testing 
Consulting/Training
Consulting/Training 
About Me 
 Microsoft Client Development MVP 
 ASPInsider 
 Twitter: @joelcochran 
 Email: joelcoc...
Consulting/Training 
About Wintellect 
Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbi...
Wintellect’s On-Demand Video Training Solution 
Try it free 
Code: <INSERT CODE HERE> WintellectNOW.com 
COCHRAN-13 
Autho...
Interview with a Method 
Consulting/Training
The Multiply Method Signature 
Int32 Multiply(Int32[] values) 
Consulting/Training
Consulting/Training 
Question #1 
What parameter(s) do you take?
Consulting/Training 
Question #2 
What value type do you return?
Consulting/Training 
Question #3 
What happens when I pass you: 
[3, 4]?
Consulting/Training 
Question #4 
What happens when I pass you: 
[7]?
Consulting/Training 
Question #5 
What happens when I pass you: 
[-5, 12, 10, -3]?
Consulting/Training 
Question #6 
What happens when I pass you: 
null?
Consulting/Training 
Question #7 
What happens when I pass you: 
[23, Int32.MaxValue]?
Consulting/Training 
Question #8 
You don’t seem to know much… 
If you don’t know the answer to these 
questions, who does...
Consulting/Training 
Why write Unit Tests? 
 Test code to ensure proper functionality given certain assumptions 
 Exerci...
Consulting/Training 
What is a Unit Test? 
 Code that tests code 
 Small discrete chunks (units) 
 One test, one condit...
What a Unit Test is Not 
Consulting/Training 
 An end-to-end test 
 Connected to live data 
 Performing external functi...
Consulting/Training 
What Not to Test 
 Network connections 
 Database Connections 
 Email/SMTP 
 Web services 
 Othe...
Anatomy of a Unit Test 
Consulting/Training 
Arrange 
• Assumptions 
• Expectations 
Act 
• Execute 
• Results 
Assert 
• ...
Consulting/Training 
Sample Unit Test 
[TestMethod] 
public void Add_PassedEmptyString_ShouldReturnZero() { 
var calc = ne...
Architecting for Unit Tests 
 Abstract external dependencies 
Consulting/Training 
 Design to an Interface 
 Overloaded...
Eating the Elephant: Unit Testing Legacy Code 
Consulting/Training 
 Identify “low hanging fruit” 
 Determine highest pr...
Consulting/Training
Consulting/Training 
Questions? 
joelcochran@gmail.com
Upcoming SlideShare
Loading in …5
×

Gentle Introduction To Unit Testing

424 views

Published on

By now you’ve heard of unit tests. Perhaps you’ve read an article about them or watched a video. Maybe you’ve even tried to write a few yourself, but the whole unit testing “thing” hasn’t quite hit home yet. Maybe you’ve been put off by the Testinistas or your company thinks unit tests are just a bunch of extra code. No matter where you are on this spectrum, if you aren’t writing unit tests as part of your daily coding, then this talk is for you. In this gentle introduction, we will discuss the value of unit tests. You will learn some practical techniques you can use to start to make unit testing part of your daily routine.

Published in: Software
  • D0WNL0AD FULL ▶ ▶ ▶ ▶ http://1lite.top/HkRu1 ◀ ◀ ◀ ◀
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Gentle Introduction To Unit Testing

  1. 1. A Gentle Introduction to Unit Testing Consulting/Training
  2. 2. Consulting/Training About Me  Microsoft Client Development MVP  ASPInsider  Twitter: @joelcochran  Email: joelcochran@gmail.com  Blog: joelcochran.com  Lead Developer, WintellectNOW
  3. 3. Consulting/Training About Wintellect Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull out all the stops to help our customers achieve their goals through advanced software-based consulting and training solutions. consulting Wintellect helps you build better software, faster, tackling the tough projects and solving the software and technology questions that help you transform your business.  Architecture, Analysis and Design  Full lifecycle software development  Debugging and Performance tuning  Database design and development training Wintellect's courses are written and taught by some of the biggest and most respected names in the Microsoft programming industry.  Learn from the best. Access the same training Microsoft’s developers enjoy  Real world knowledge and solutions on both current and cutting edge technologies  Flexibility in training options – onsite, virtual, on demand who we are
  4. 4. Wintellect’s On-Demand Video Training Solution Try it free Code: <INSERT CODE HERE> WintellectNOW.com COCHRAN-13 Authors Enjoy:  Royalty Income  Personal Branding  Cross-Sell Opps  Free library access Subscribers Enjoy:  Expert Instructors  Quality Content  Practical Application  All Devices Consulting/Training Individuals | Businesses | Enterprise Organizations
  5. 5. Interview with a Method Consulting/Training
  6. 6. The Multiply Method Signature Int32 Multiply(Int32[] values) Consulting/Training
  7. 7. Consulting/Training Question #1 What parameter(s) do you take?
  8. 8. Consulting/Training Question #2 What value type do you return?
  9. 9. Consulting/Training Question #3 What happens when I pass you: [3, 4]?
  10. 10. Consulting/Training Question #4 What happens when I pass you: [7]?
  11. 11. Consulting/Training Question #5 What happens when I pass you: [-5, 12, 10, -3]?
  12. 12. Consulting/Training Question #6 What happens when I pass you: null?
  13. 13. Consulting/Training Question #7 What happens when I pass you: [23, Int32.MaxValue]?
  14. 14. Consulting/Training Question #8 You don’t seem to know much… If you don’t know the answer to these questions, who does?
  15. 15. Consulting/Training Why write Unit Tests?  Test code to ensure proper functionality given certain assumptions  Exercise code without running the app  Write once, run a million times  Guards against unintended consequences  Tests define success
  16. 16. Consulting/Training What is a Unit Test?  Code that tests code  Small discrete chunks (units)  One test, one condition  Based on assumptions  Should be automated and repeatable
  17. 17. What a Unit Test is Not Consulting/Training  An end-to-end test  Connected to live data  Performing external functions (like sending an Email)  User tests
  18. 18. Consulting/Training What Not to Test  Network connections  Database Connections  Email/SMTP  Web services  Other people’s code
  19. 19. Anatomy of a Unit Test Consulting/Training Arrange • Assumptions • Expectations Act • Execute • Results Assert • Compare • Report
  20. 20. Consulting/Training Sample Unit Test [TestMethod] public void Add_PassedEmptyString_ShouldReturnZero() { var calc = new StringCalculator(); var expected = 0; int actual = calc.Add(String.Empty); Assert.AreEqual(expected, actual); }
  21. 21. Architecting for Unit Tests  Abstract external dependencies Consulting/Training  Design to an Interface  Overloaded Constructors  Inversion of Control (IOC) Containers
  22. 22. Eating the Elephant: Unit Testing Legacy Code Consulting/Training  Identify “low hanging fruit”  Determine highest priority elements  Locate external dependencies  Be reasonable
  23. 23. Consulting/Training
  24. 24. Consulting/Training Questions? joelcochran@gmail.com

×