SlideShare a Scribd company logo
TDD: Test Driven Developmentwith Visual Studio 2010Stefano Paluellostefano.paluello@pastesoft.comhttp://stefanopaluello.wordpress.comTwitter: @palutz
Test Driven DevelopmentTest-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: the developer writes a failing automated test case that defines a desired improvement or new function (RED)produces code to pass that test (GREEN)finally refactors the new code to acceptable standards (REFACTOR)[Wikipedia]
Test Driven DevelopmentTest Driven Development is one of the Extreme Programming principles (actually is the first one), but can be used also by itselfTDD is a CHANGE OF APPROACH for developers, is a new MINDSET, from writing code and then testing it (if there is enough time) to writing the test first and then writing the code to satisfy the test
Why do I need TDD?
Before TDD…The industry “standard” behavior was to write the code, and then write the tests. This leads to lots of applications without tests at allAlso the “good” applications with some tests written, weren’t (aren’t!!!) able to know whether the new code has broken the existing features
Typical result?
The new approach…Why do we have to stick on that plan?Kent Beck introduced a new method, inside his book about Extreme Programming (XP), in which he proposed to reverse this order by starting with unit tests and then writing the implementation.
Why TDD is good?Thinking about the tests pushes the developer to understand better the gathered requirementsWith the tests defined, the developer can focus on writing ONLY the code to satisfy them (reduce the over-engineered code, or dead-code)The unit tests help to check that any new modification won’t break the existing features
TDD is good (2)TDD speed-up your code! Ok, writing a whole set of code to test your program could appear as too much work, but with test you can trust your code more and you can have a quick feedback about your design and how your objects behave. When all tests have succeeded, you don’t need to spend so much time debugging the tested code.
TDD is notTest Driven Development is good, not God! Test Driven Development isn’t a magic stick that will solve ALL your problemsTest Driven Development is not working if there is not a REALLY mind shift
TDD != Unit Test Ok, this could be a bit confusing but…Test Driven Development is a process, is a mindset, a different approach, focusing on isolated test case to drive designUnit Test is a procedure, a part of the test process
How to justify TDD to PM	Microsoft just published a research report where was pointed out that using TDD, the bugs and defects are reduced from 40% to 90% (nice code was made before!  )http://research.microsoft.com/en-us/groups/ese/nagappan_tdd.pdf
How to justify TDD to Dev Team LeadTDD increase the software’s flexibilityTo be testable, a codebase using TDD is more decoupled and for this reason also adding more features is easier
How to justify TDD to…Stop thinking and justify!Just CODE!
Ops, some advices before code…Write simple test that verify only ONE behaviorAvoid dependencies between testsOne test class for every class within the production codeUse test initialization code before and test cleanup code after running your test (sealed context)Verify that all the tests are passed before move to another feature testMaximize the number of automated tests
TDD with Visual Studio
DemoUnit test with Visual Studio 2010
Demo RecapDespite the Intellisense, Visual Studio 2010 has some tools that help you to focus on TDDUsing Code Coverage, Visual Studio will show you the effectiveness of your tests
DemoWeb test with Visual Studio 2010
Some test “tools” for VS2010Code Contractsallow you to explicitly declare the preconditions, postconditions and invariant part of your codethis improves also the testing via runtime checking (injecting the contracts)it comes from Devlabs and it was an external assemblies for .Net 3.5, now included in .Net 4.0
VS2010 tools (2)Pex and MolesInside the Visual Studio 2010 Power tools extensionPex automatically generates test suites with high code coverage.Right from the Visual Studio code editor, Pex finds interesting input-output values of your methods (white box testing), which you can save as a small test suite with high code coverage. Microsoft Pex is a Visual Studio add-in for testing .NET Framework applications.Moles allows to replace any .NET method with a delegate. Moles supports unit testing by providing isolation by way of detours and stubs. The Moles framework is provided with Pex, or can be installed by itself as a Microsoft Visual Studio add-in (example test Asp.Net and Sharepoint applications!)
Contracts and Pex together
&Programmazione per Device:da Embedded a DesktopDomande  & Risposte

More Related Content

PPT
Testing and Mocking Object - The Art of Mocking.
ODP
Embrace Unit Testing
PDF
Unit Testing 101
PDF
Unit Testing
PPTX
Unit Tests And Automated Testing
PPTX
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
ODP
Testing In Java
Testing and Mocking Object - The Art of Mocking.
Embrace Unit Testing
Unit Testing 101
Unit Testing
Unit Tests And Automated Testing
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Testing In Java

What's hot (20)

PPS
Why Unit Testingl
PPTX
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
PPTX
Unit Testing in Java
PDF
iOS Test-Driven Development
PPS
JUnit Presentation
PPTX
Principles and patterns for test driven development
PPTX
Unit tests and TDD
PDF
Software Testing
PDF
Testing Java applications with Maveryx
DOCX
Test driven development and unit testing with examples in C++
PPTX
Test-Driven Development
PPT
PPTX
Unit Testing Full@
PDF
Unit and integration Testing
PDF
Test Driven Development (TDD)
PDF
Behavior Driven Development with SpecFlow
PDF
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
PDF
Write readable tests
PPTX
Tdd & unit test
PPTX
Unit Testing Android Applications
Why Unit Testingl
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Unit Testing in Java
iOS Test-Driven Development
JUnit Presentation
Principles and patterns for test driven development
Unit tests and TDD
Software Testing
Testing Java applications with Maveryx
Test driven development and unit testing with examples in C++
Test-Driven Development
Unit Testing Full@
Unit and integration Testing
Test Driven Development (TDD)
Behavior Driven Development with SpecFlow
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
Write readable tests
Tdd & unit test
Unit Testing Android Applications
Ad

Similar to TDD with Visual Studio 2010 (20)

PPTX
Test-Driven Development In Action
PPTX
Test-Driven Development
PPTX
Test driven development in .Net - 2010 + Eclipse
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test Driven Development
PDF
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
PPT
Test Driven Development
PPTX
VT.NET 20160411: An Intro to Test Driven Development (TDD)
PPTX
TDD in Agile
PPT
TDD (Test Driven Design)
PPTX
Test Driven Development
PDF
PPTX
Tdd is not about testing (OOP)
PPT
Test-Driven Development
Test-Driven Development In Action
Test-Driven Development
Test driven development in .Net - 2010 + Eclipse
Test driven development
Test driven development
Test driven development
Test driven development
Test driven development
Test driven development
Test Driven Development
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
Test Driven Development
VT.NET 20160411: An Intro to Test Driven Development (TDD)
TDD in Agile
TDD (Test Driven Design)
Test Driven Development
Tdd is not about testing (OOP)
Test-Driven Development
Ad

More from Stefano Paluello (10)

PPTX
Clinical Data and AI
PPTX
Real scenario: moving a legacy app to the Cloud
PPTX
A gentle introduction to the world of BigData and Hadoop
PPTX
PDF
How to use asana
PPTX
Using MongoDB with the .Net Framework
PDF
Windows Azure Overview
PPTX
Asp.Net MVC Intro
PPTX
Entity Framework 4
PPTX
Teamwork and agile methodologies
Clinical Data and AI
Real scenario: moving a legacy app to the Cloud
A gentle introduction to the world of BigData and Hadoop
How to use asana
Using MongoDB with the .Net Framework
Windows Azure Overview
Asp.Net MVC Intro
Entity Framework 4
Teamwork and agile methodologies

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PPTX
Cloud computing and distributed systems.
PPT
Teaching material agriculture food technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Machine learning based COVID-19 study performance prediction
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Encapsulation theory and applications.pdf
Cloud computing and distributed systems.
Teaching material agriculture food technology
NewMind AI Weekly Chronicles - August'25 Week I
Machine learning based COVID-19 study performance prediction
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
Per capita expenditure prediction using model stacking based on satellite ima...
Advanced methodologies resolving dimensionality complications for autism neur...
Mobile App Security Testing_ A Comprehensive Guide.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Monthly Chronicles - July 2025
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
CIFDAQ's Market Insight: SEC Turns Pro Crypto

TDD with Visual Studio 2010

  • 1. TDD: Test Driven Developmentwith Visual Studio 2010Stefano Paluellostefano.paluello@pastesoft.comhttp://stefanopaluello.wordpress.comTwitter: @palutz
  • 2. Test Driven DevelopmentTest-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: the developer writes a failing automated test case that defines a desired improvement or new function (RED)produces code to pass that test (GREEN)finally refactors the new code to acceptable standards (REFACTOR)[Wikipedia]
  • 3. Test Driven DevelopmentTest Driven Development is one of the Extreme Programming principles (actually is the first one), but can be used also by itselfTDD is a CHANGE OF APPROACH for developers, is a new MINDSET, from writing code and then testing it (if there is enough time) to writing the test first and then writing the code to satisfy the test
  • 4. Why do I need TDD?
  • 5. Before TDD…The industry “standard” behavior was to write the code, and then write the tests. This leads to lots of applications without tests at allAlso the “good” applications with some tests written, weren’t (aren’t!!!) able to know whether the new code has broken the existing features
  • 7. The new approach…Why do we have to stick on that plan?Kent Beck introduced a new method, inside his book about Extreme Programming (XP), in which he proposed to reverse this order by starting with unit tests and then writing the implementation.
  • 8. Why TDD is good?Thinking about the tests pushes the developer to understand better the gathered requirementsWith the tests defined, the developer can focus on writing ONLY the code to satisfy them (reduce the over-engineered code, or dead-code)The unit tests help to check that any new modification won’t break the existing features
  • 9. TDD is good (2)TDD speed-up your code! Ok, writing a whole set of code to test your program could appear as too much work, but with test you can trust your code more and you can have a quick feedback about your design and how your objects behave. When all tests have succeeded, you don’t need to spend so much time debugging the tested code.
  • 10. TDD is notTest Driven Development is good, not God! Test Driven Development isn’t a magic stick that will solve ALL your problemsTest Driven Development is not working if there is not a REALLY mind shift
  • 11. TDD != Unit Test Ok, this could be a bit confusing but…Test Driven Development is a process, is a mindset, a different approach, focusing on isolated test case to drive designUnit Test is a procedure, a part of the test process
  • 12. How to justify TDD to PM Microsoft just published a research report where was pointed out that using TDD, the bugs and defects are reduced from 40% to 90% (nice code was made before!  )http://research.microsoft.com/en-us/groups/ese/nagappan_tdd.pdf
  • 13. How to justify TDD to Dev Team LeadTDD increase the software’s flexibilityTo be testable, a codebase using TDD is more decoupled and for this reason also adding more features is easier
  • 14. How to justify TDD to…Stop thinking and justify!Just CODE!
  • 15. Ops, some advices before code…Write simple test that verify only ONE behaviorAvoid dependencies between testsOne test class for every class within the production codeUse test initialization code before and test cleanup code after running your test (sealed context)Verify that all the tests are passed before move to another feature testMaximize the number of automated tests
  • 17. DemoUnit test with Visual Studio 2010
  • 18. Demo RecapDespite the Intellisense, Visual Studio 2010 has some tools that help you to focus on TDDUsing Code Coverage, Visual Studio will show you the effectiveness of your tests
  • 19. DemoWeb test with Visual Studio 2010
  • 20. Some test “tools” for VS2010Code Contractsallow you to explicitly declare the preconditions, postconditions and invariant part of your codethis improves also the testing via runtime checking (injecting the contracts)it comes from Devlabs and it was an external assemblies for .Net 3.5, now included in .Net 4.0
  • 21. VS2010 tools (2)Pex and MolesInside the Visual Studio 2010 Power tools extensionPex automatically generates test suites with high code coverage.Right from the Visual Studio code editor, Pex finds interesting input-output values of your methods (white box testing), which you can save as a small test suite with high code coverage. Microsoft Pex is a Visual Studio add-in for testing .NET Framework applications.Moles allows to replace any .NET method with a delegate. Moles supports unit testing by providing isolation by way of detours and stubs. The Moles framework is provided with Pex, or can be installed by itself as a Microsoft Visual Studio add-in (example test Asp.Net and Sharepoint applications!)
  • 22. Contracts and Pex together
  • 23. &Programmazione per Device:da Embedded a DesktopDomande & Risposte