Test-Driven Development José Almeida, Microsoft

Slides:



Advertisements
Similar presentations
A Brief Introduction to Test- Driven Development Shawn M. Jones.
Advertisements

Improving Testability Dave Catlett Test Architect, Microsoft
1 CS 426 Senior Projects Chapter 19: Interfaces and Components [Arlow & Neustadt 2005] February 28, 2008.
CSE3030Lecture 11 Know Your User The First Slogan.
Kashif Jalal CA-240 (072) Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 2 of…
Object Oriented Development and Practices In SharePoint Mostly.
ESupport Shifting Customers to the Internet for Support Published: January 2002.
Test-Driven Development “Test first, develop later!” –OCUnit.
Test Driven Development Derived from Dr. Fawcett’s notes Phil Pratt-Szeliga Fall 2009.
Red-Green-Refactor! EclipseCon 2008 Kevin P. Taylor, Nicolaus Malnick Test-Driven Development (TDD) for Eclipse RCP.
Microsoft Visual Basic 2012 CHAPTER ONE Introduction to Visual Basic 2012 Programming.
Test-Driven Development With Visual Studio 2005 Erno de Weerd Info Support.
Test Driven Development using Visual Studio Team System Ariel Gur-Arieh VP R&D – MCD Software Solutions
Test Driven Development An approach to writing better code Jimmy Zimmerman Intel Corporation.
A First Program Using C#
Design for Testability: Mocks, Stubs, Refactoring, and User Interfaces Benjamin Day.
The Design Discipline.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
DEV334 Creating Application Starting Points & Sharing Best Practices with Enterprise Templates Marc Gusmano Director of Emerging Technologies The Information.
Presenter - Donn Felker.  Senior Consultant for Microsoft Gold Certified Partner- Statêra.  8 years of experience in developing and architecting enterprise.
DEV302 - Visual Studio Team System Building Robust and Reliable Software Eric Lee Program Manager Microsoft Corporation.
@benday #vslive Better Unit Tests through Design Patterns: Repository, Adapter, Mocks, and more… Benjamin
MVC and MVP. References enter.html enter.html
Developing Workflows with SharePoint Designer David Coe Application Development Consultant Microsoft Corporation.
Todd Snyder Development Team Lead Infragistics Experience Design Group.
Sadegh Aliakbary Sharif University of Technology Spring 2012.
© Copyright 2005, thycotic. Test Driven Development Jonathan Cogley Maryland Cold Fusion User's Group 10/11/2005.
DEV325 Deploying Visual Studio.NET Applications Billy Hollis Author / Consultant.
Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 1 Test-Driven Development An introduction for C# developers.
© ALEXANDRE CUVA  VERSION 2.00 Test Driven Design.
Test Driven Development Arrange, Act, Assert… Awesome Jason Offutt Software Engineer Central Christian Church
By for Testing Tools: Test Automation and supporting tools Jariro Pava, Robert Vanderwall 1 WISTPC-14.
Component Technology. Challenges Facing the Software Industry Today’s applications are large & complex – time consuming to develop, difficult and costly.
Refactoring An Automated Tool for the Tiger Language Leslie A Hensley
Systems Analysis and Design in a Changing World, 3rd Edition
DEV337 Modeling Distributed Enterprise Applications Using UML in Visual Studio.NET David Keogh Program Manager Visual Studio Enterprise Tools.
DEV322 Unit Testing Best Practices With Visual Studio 2005 Team System Mark Seemann Senior Consultant Microsoft Consulting Services.
First BlueJ Day Houston, 2006 Unit Testing with BlueJ Bruce Quig Deakin University.
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.
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.
Microsoft Dynamics NAV 2009 and Architecture Overview Name Title Microsoft Corporation.
Code Development Code development for end user systems.
Software Design: Principles, Process, and Concepts Getting Started with Design.
1.
Copyright © 2005 Charlie Poole. All rights reserved Test First User Interfaces XP2005 Sheffield University June 18, 2005.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Refactoring - 1 CS494: Intro. to Refactoring Readings: –Refactoring for everyone: How and why to use Eclipse's automated refactoring features. By David.
Scalatest. 2 Test-Driven Development (TDD) TDD is a technique in which you write the tests before you write the code you want to test This seems backward,
Dave Lloyd Unit Testing in the Real World.
1 Presentation Title Test-driven development (TDD) Overview David Wu.
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.
Northwest Arkansas.Net User Group Jay Smith Tyson Foods, Inc. Unit Testing nUnit, nUnitAsp, nUnitForms.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
1 © Agitar Software, 2007 Automated Unit Testing with AgitarOne Presented by Eamon McCormick Senior Solutions Consultant, Agitar Software Inc. Presented.
INF230 Basics in C# Programming
Test-driven development
Unit Testing with xUnit.net
Low Budget Productions, LLC
Test Driven Development
Test Driven Development 1 November Agenda  What is TDD ?  Steps to start  Refactoring  TDD terminology  Benefits  JUnit  Mocktio  Continuous.
Visual Studio Tools for Office 2005
Software Architecture
What's New in Visual Studio 2005
Visual Studio 2005 Tools For Office: Creating A Multi-tier Application
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Designing For Testability
PnP Partner Pack - Introduction
Presentation transcript:

Test-Driven Development José Almeida, Microsoft

Outline What is TDD? What is TDD? TDD in Practice TDD in Practice Endo-Testing Endo-Testing Test-Driven UI Development Test-Driven UI Development Conclusion Conclusion

Test-Driven Development (TDD) Is a programming practice Is a programming practice Unit tests are written before the domain code Unit tests are written before the domain code Namely: Namely:  Write a test that fails  Write code to make the test pass  Refactor Unit Tests and Refactoring are the tools of TDD Unit Tests and Refactoring are the tools of TDD

Unit Tests Test specific aspects of a functionality Test specific aspects of a functionality Execute rapidly Execute rapidly Independent of each other Independent of each other Independent of the surrounding environment Independent of the surrounding environment Independent of execution order Independent of execution order Automated Automated

Refactoring Change the internal structure of the code without changing it’s external behavior. Change the internal structure of the code without changing it’s external behavior. Associated with arithmetic factorization: Associated with arithmetic factorization: ab + ac = a(b+c) Same result but the expression is simplified. Same result but the expression is simplified.

Test List Task Based Task Based  4-8 hour duration  minute exercise at beginning Brainstorm a list of unit tests Brainstorm a list of unit tests Do not get hung up on completeness, you can always add more later Do not get hung up on completeness, you can always add more later Describes completion requirements Describes completion requirements

Red/Green/Refactor Write a test for new capability Start Compile Fix compile errors Run the test And see it fail Write the code Run the test And see it pass Refactor as needed

Financial Service Financial Service  A simple application that implements the following set of functionality:  Credit an Account  Debit an Account

Characteristics of TDD TDD promotes code testability TDD promotes code testability Testability is related to: Testability is related to:  Strong cohesion  Loose coupling  No redundancy  Encapsulation These are good programming practices These are good programming practices Striving for good tests results in better code Striving for good tests results in better code

TDD Tenets Never write a single line of code unless you have a failing unit test Never write a single line of code unless you have a failing unit test Eliminate Duplication (Refactor mercilessly) Eliminate Duplication (Refactor mercilessly)

Observation It’s harder to write unit tests for components located at the “edge” of the system: It’s harder to write unit tests for components located at the “edge” of the system:  Web Services  Data Access Layer  User Interface

Mock Objects Inherent challenges in testing dependant objects Inherent challenges in testing dependant objects  Objects dependant on ephemeral objects produce unpredictable behavior  User Interfaces, Databases and the like are inherently ephemeral

Example How can we write a test for GetRate() when the result of FinancialServicesWS.GetRate() is unpredictable? How can we write a test for GetRate() when the result of FinancialServicesWS.GetRate() is unpredictable? Money +GetRate(string from, string to):double FinancialServices WS +GetRate(string from, string to):double

Mock Objects Solution: Solution:  Replace the unpredictable object with a testing version that produces predictable results FinancialServicesWS +GetRate(string from, string to):double MockFinancialServicesWS +GetRate(string from, string to):double IFinancialServicesWS +GetRate(string from, string to):double

Steps to create a Dynamic Mock Object with DotNetMock 1. FinancialServicesWS is a proxy generated from the WSDL of the web service. Refactor the proxy to extract an interface: IFinancialServicesWS 2. Create a controller based on the extracted interface 3. Have the controller create a dynamic mock object 4. Specify the expected behavior of the mock object 5. Use the mock object in place of the real object in the test

Creating a Dynamic Mock Object

Conclusion Advantages of Mock Objects: Advantages of Mock Objects:  Promote design to interfaces  Promote testability and isolation of tests  Promote decoupling Challenges of Mock Objects: Challenges of Mock Objects:  More classes to maintain  Requires breaking encapsulation to replace real object with mock object, sometimes resulting in less “elegant” code

User Interfaces Difficult to write automated tests to, because they are designed to be exercised by a user and often hide their programmatic interface. Difficult to write automated tests to, because they are designed to be exercised by a user and often hide their programmatic interface. Inherent challenges in testing Windows Forms applications: Inherent challenges in testing Windows Forms applications:  Are highly coupled .Exe assemblies cannot be referenced from the IDE

NUnitForms NUnit Extension for testing Windows Forms applications NUnit Extension for testing Windows Forms applications

Steps to test a WinForms App 1. Place the forms in a separate class library 2. Create an Application Launcher that executes the forms 3. Reference the class library that contains the forms in the Test assembly 4. Design the Form 5. Use NUnitForms to write the tests 6. Write the code to pass the tests

Unit Testing Windows Forms

Conclusion Advantages: Advantages:  Easy to implement  Development of UI can be completely test- driven  Promotes decoupling  Enables creation of automated User Acceptance Tests Challenges: Challenges:  Setup requires somewhat complex wiring

References “Test-Driven Development By Example”, Kent Beck “Test-Driven Development By Example”, Kent Beck “Test-Driven Development in Microsoft.NET”, James Newkirk, Alexei Vorontsov “Test-Driven Development in Microsoft.NET”, James Newkirk, Alexei Vorontsov “Refactoring, Improving The Design Of Existing Code”, Martin Fowler “Refactoring, Improving The Design Of Existing Code”, Martin Fowler “Patterns Of Enterprise Application Architecture”, Martin Fowler “Patterns Of Enterprise Application Architecture”, Martin Fowler “The Humble Dialog Box”, alogBox.pdf “The Humble Dialog Box”, alogBox.pdf alogBox.pdf alogBox.pdf

Resources Visual Studio.NET 2005 Visual Studio.NET 2005  Visual Studio.NET 2003 Project Templates for NUnit: Visual Studio.NET 2003 Project Templates for NUnit:  NUnit NUnit  DotNetMock DotNetMock  NUnitForms NUnitForms  C# Refactory C# Refactory  ReSharper ReSharper 

Q & A

© 2002 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.