SlideShare ist ein Scribd-Unternehmen logo
1 von 23
TDD: Test Driven Developmentwith Visual Studio 2010 Stefano Paluello stefano.paluello@pastesoft.com http://stefanopaluello.wordpress.com Twitter: @palutz
Test Driven Development Test-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 Development Test Driven Development is one of the Extreme Programming principles (actually is the first one), but can be used also by itself TDD 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 all Also 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 requirements With 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 not Test Driven Development is good, not God!  Test Driven Development isn’t a magic stick that will solve ALL your problems Test 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 design Unit 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 Lead TDD increase the software’s flexibility To 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 behavior Avoid dependencies between tests One test class for every class within the production code Use 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 test Maximize the number of automated tests
TDD with Visual Studio
Demo Unit test with Visual Studio 2010
Demo Recap Despite the Intellisense, Visual Studio 2010 has some tools that help you to focus on TDD Using Code Coverage, Visual Studio will show you the effectiveness of your tests
Demo Web test with Visual Studio 2010
Some test “tools” for VS2010 Code Contracts allow you to explicitly declare the preconditions, postconditions and invariant part of your code this 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 Moles Inside the Visual Studio 2010 Power tools extension Pex 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 Desktop Domande  & Risposte

Weitere ähnliche Inhalte

Was ist angesagt?

Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
Alex Borsuk
 

Was ist angesagt? (20)

Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Testing Java applications with Maveryx
Testing Java applications with MaveryxTesting Java applications with Maveryx
Testing Java applications with Maveryx
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
J Unit
J UnitJ Unit
J Unit
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlow
 
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAUTest Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
 
Write readable tests
Write readable testsWrite readable tests
Write readable tests
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 

Ähnlich wie TDD with Visual Studio 2010

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
bhochhi
 

Ähnlich wie TDD with Visual Studio 2010 (20)

Tutorial test driven development with Visual Studio 2012
Tutorial test driven development with Visual Studio 2012Tutorial test driven development with Visual Studio 2012
Tutorial test driven development with Visual Studio 2012
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
The Essentials Of Test Driven Development
The Essentials Of Test Driven Development The Essentials Of Test Driven Development
The Essentials Of Test Driven Development
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and Adoption
 
Tdd
TddTdd
Tdd
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
 
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose presoTest Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
 
Presentation_TDD
Presentation_TDDPresentation_TDD
Presentation_TDD
 
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd   seven years afterIan Cooper webinar for DDD Iran: Kent beck style tdd   seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
 
Test driven development and react js application go hand in hand
Test driven development and react js application go hand in handTest driven development and react js application go hand in hand
Test driven development and react js application go hand in hand
 
xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012
 
TDD- Test Driven Development
TDD- Test Driven DevelopmentTDD- Test Driven Development
TDD- Test Driven Development
 
Test driven development(tdd)
Test driven development(tdd)Test driven development(tdd)
Test driven development(tdd)
 
A Study: The Analysis of Test Driven Development And Design Driven Test
A Study: The Analysis of Test Driven Development And Design Driven TestA Study: The Analysis of Test Driven Development And Design Driven Test
A Study: The Analysis of Test Driven Development And Design Driven Test
 
Python and test
Python and testPython and test
Python and test
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 

Mehr von Stefano Paluello (10)

Clinical Data and AI
Clinical Data and AIClinical Data and AI
Clinical Data and AI
 
Real scenario: moving a legacy app to the Cloud
Real scenario: moving a legacy app to the CloudReal scenario: moving a legacy app to the Cloud
Real scenario: moving a legacy app to the Cloud
 
A gentle introduction to the world of BigData and Hadoop
A gentle introduction to the world of BigData and HadoopA gentle introduction to the world of BigData and Hadoop
A gentle introduction to the world of BigData and Hadoop
 
Grandata
GrandataGrandata
Grandata
 
How to use asana
How to use asanaHow to use asana
How to use asana
 
Using MongoDB with the .Net Framework
Using MongoDB with the .Net FrameworkUsing MongoDB with the .Net Framework
Using MongoDB with the .Net Framework
 
Windows Azure Overview
Windows Azure OverviewWindows Azure Overview
Windows Azure Overview
 
Asp.Net MVC Intro
Asp.Net MVC IntroAsp.Net MVC Intro
Asp.Net MVC Intro
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
 
Teamwork and agile methodologies
Teamwork and agile methodologiesTeamwork and agile methodologies
Teamwork and agile methodologies
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

TDD with Visual Studio 2010

  • 1. TDD: Test Driven Developmentwith Visual Studio 2010 Stefano Paluello stefano.paluello@pastesoft.com http://stefanopaluello.wordpress.com Twitter: @palutz
  • 2. Test Driven Development Test-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 Development Test Driven Development is one of the Extreme Programming principles (actually is the first one), but can be used also by itself TDD 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 all Also 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 requirements With 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 not Test Driven Development is good, not God!  Test Driven Development isn’t a magic stick that will solve ALL your problems Test 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 design Unit 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 Lead TDD increase the software’s flexibility To 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 behavior Avoid dependencies between tests One test class for every class within the production code Use 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 test Maximize the number of automated tests
  • 16. TDD with Visual Studio
  • 17. Demo Unit test with Visual Studio 2010
  • 18. Demo Recap Despite the Intellisense, Visual Studio 2010 has some tools that help you to focus on TDD Using Code Coverage, Visual Studio will show you the effectiveness of your tests
  • 19. Demo Web test with Visual Studio 2010
  • 20. Some test “tools” for VS2010 Code Contracts allow you to explicitly declare the preconditions, postconditions and invariant part of your code this 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 Moles Inside the Visual Studio 2010 Power tools extension Pex 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 Desktop Domande & Risposte