SlideShare a Scribd company logo
1 of 20
Effective Test Driven Development & Unit Testing with Visual Studio 2010 Abhimanyu Singhal Lead Consultant iMentor Knowledge Services
About Me History First Laid Hands on Computers in 1994 – Been a Geek for Quite Some time Worked on different platforms and technologies Career Focus – Embedded Systems and Native Development Currently Help companies use Visual Studio Team System as an ALM Platform High-End Technical Consultancy and Training
Objectives
Why is TDD Good Thinking about tests pushes developer to understand better the gathered requirements Reduces the over engineered code (dead code) Unit Tests help to check that any new modification wont break the existing features. TDD increases software flexibility TDD code is more decoupled
Demo – TDD for a Stack
Visual Studio Team Test A Visual Studio integrated unit-testing framework Code generation of test method stubs.  Running tests within the IDE.  Incorporation of test data loaded from a database.  Code coverage analysis once the tests have run.
TestMethodAttribute Class Designates a Method as a Test Method Found in Microsoft.VisualStudio.QualityTools.UnitTesting.Framework Namespace TestMethod has to be an instance method with no paramters Method name is irrelevant because reflection searches for TestMethod Attribute
TestClassAttribute Class Class containing the test method is designated TestClass Attribute ,[object Object]
Team Test Uses Reflection to find Class with TestClass Attribute and Method with TestMethod Attribute and runs it,[object Object]
ExpectedException Attribute Takes a Parameter which is Exception Type to watch for If Exception does not occur test fails The Second parameter (string) is optional is the error message displayed when exception is not thrown
Loading Test Data From Database Use Test Properties Window Add TestData Attribute Source Type Connection String TableName DataAccessMethod
The TestContext Provides associated data through  DataRow Property TestDirectory, TestName Mesuring Test Time using  BeingTimer()  EndTimer()
Code Coverage Determines how much code is tested Shows Percentage of Code Executed Highlights code to show which lines are executed
Initializing and Cleaning Up Tests TestInitialize Attribute TestCleanup Attribute Code to be run before and after each test method Other Attributes for Lifetime Methods AssemblyInitializeAttribute/AssemblyCleanupAttribute ClassInitializeAttribute/ClassCleanupAttribute.
The Testing Framework
Guidance – Unit Testing Keep Testing Code in Separate Assemblies Check for cleanup during test setup and execute the cleanup prior to the setup as necessary Avoid creating dependencies between tests, each test should be autonomous.  Create one test class corresponding to each class within the production code. Avoid creating other machine dependent tests Create mock objects to test interfaces
Question and Answers Session
Thank You abhimanyu@imentor.co.in @abhi_singhal http://www.imentor.co.in/blog
iMentor Knowledge Services

More Related Content

What's hot (20)

Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Unit testing
Unit testingUnit testing
Unit testing
 
Moq presentation
Moq presentationMoq presentation
Moq presentation
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
N Unit Presentation
N Unit PresentationN Unit Presentation
N Unit Presentation
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminar
 
Unit testing with NUnit
Unit testing with NUnitUnit testing with NUnit
Unit testing with NUnit
 
NUnit Features Presentation
NUnit Features PresentationNUnit Features Presentation
NUnit Features Presentation
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 
S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discovering
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
 
Unit test
Unit testUnit test
Unit test
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Unit test
Unit testUnit test
Unit test
 
Xp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And MocksXp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And Mocks
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile Apps
 

Viewers also liked

T-38 TALON MOVE
T-38 TALON MOVE T-38 TALON MOVE
T-38 TALON MOVE Curt Howard
 
UNION TRIBUNE 8 6 2003
UNION TRIBUNE 8 6 2003UNION TRIBUNE 8 6 2003
UNION TRIBUNE 8 6 2003Curt Howard
 
And Then There Was One
And Then There Was OneAnd Then There Was One
And Then There Was OneLoretto Leary
 
10 interview tips for green card visa applicants
10 interview tips for green card visa applicants10 interview tips for green card visa applicants
10 interview tips for green card visa applicantsilexlaw pllc
 
Curso adm 195 planificación y control de proyectos
Curso adm 195   planificación y control de proyectosCurso adm 195   planificación y control de proyectos
Curso adm 195 planificación y control de proyectosProcasecapacita
 
JOHN SMALL RECOMENDATION
JOHN SMALL RECOMENDATIONJOHN SMALL RECOMENDATION
JOHN SMALL RECOMENDATIONCurt Howard
 
TestNet 2016 - Improving Your Selenium WebDriver Tests
TestNet 2016 - Improving Your Selenium WebDriver TestsTestNet 2016 - Improving Your Selenium WebDriver Tests
TestNet 2016 - Improving Your Selenium WebDriver TestsRoy de Kleijn
 
electronics-embedded-project-topics-list-softroniics
electronics-embedded-project-topics-list-softroniicselectronics-embedded-project-topics-list-softroniics
electronics-embedded-project-topics-list-softroniicsshanofa sanu
 
екскурзия до плевенEr point presentation (2)
екскурзия до плевенEr point presentation (2)екскурзия до плевенEr point presentation (2)
екскурзия до плевенEr point presentation (2)Ivanka Lekova
 

Viewers also liked (12)

Numeros
NumerosNumeros
Numeros
 
T-38 TALON MOVE
T-38 TALON MOVE T-38 TALON MOVE
T-38 TALON MOVE
 
UNION TRIBUNE 8 6 2003
UNION TRIBUNE 8 6 2003UNION TRIBUNE 8 6 2003
UNION TRIBUNE 8 6 2003
 
And Then There Was One
And Then There Was OneAnd Then There Was One
And Then There Was One
 
10 interview tips for green card visa applicants
10 interview tips for green card visa applicants10 interview tips for green card visa applicants
10 interview tips for green card visa applicants
 
Curso adm 195 planificación y control de proyectos
Curso adm 195   planificación y control de proyectosCurso adm 195   planificación y control de proyectos
Curso adm 195 planificación y control de proyectos
 
Abstract 3
Abstract 3Abstract 3
Abstract 3
 
JOHN SMALL RECOMENDATION
JOHN SMALL RECOMENDATIONJOHN SMALL RECOMENDATION
JOHN SMALL RECOMENDATION
 
METRO MAGAZINE
METRO MAGAZINE METRO MAGAZINE
METRO MAGAZINE
 
TestNet 2016 - Improving Your Selenium WebDriver Tests
TestNet 2016 - Improving Your Selenium WebDriver TestsTestNet 2016 - Improving Your Selenium WebDriver Tests
TestNet 2016 - Improving Your Selenium WebDriver Tests
 
electronics-embedded-project-topics-list-softroniics
electronics-embedded-project-topics-list-softroniicselectronics-embedded-project-topics-list-softroniics
electronics-embedded-project-topics-list-softroniics
 
екскурзия до плевенEr point presentation (2)
екскурзия до плевенEr point presentation (2)екскурзия до плевенEr point presentation (2)
екскурзия до плевенEr point presentation (2)
 

Similar to Unit testing and test driven development using vs

Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Mohamed Taman
 
12 Rational Solo Pruebas 2009
12 Rational Solo Pruebas 200912 Rational Solo Pruebas 2009
12 Rational Solo Pruebas 2009Pepe
 
justin presentation upload PPT june 19
justin presentation upload PPT june 19justin presentation upload PPT june 19
justin presentation upload PPT june 19techweb08
 
justin for ppt1 by browse button
justin for ppt1 by browse buttonjustin for ppt1 by browse button
justin for ppt1 by browse buttontechweb08
 
upload ppt by browse button
upload ppt by browse buttonupload ppt by browse button
upload ppt by browse buttontechweb08
 
justin presentation Slideshare PPT upload June 25 Final one
justin presentation Slideshare PPT upload June 25 Final onejustin presentation Slideshare PPT upload June 25 Final one
justin presentation Slideshare PPT upload June 25 Final onetechweb08
 
upload ppt1 by browse button
upload ppt1 by browse buttonupload ppt1 by browse button
upload ppt1 by browse buttontechweb08
 
upload ppt by browse button
upload ppt by browse buttonupload ppt by browse button
upload ppt by browse buttontechweb08
 
Justin Presentation PPT Upload June 25 adv
Justin Presentation PPT Upload June 25 advJustin Presentation PPT Upload June 25 adv
Justin Presentation PPT Upload June 25 advtechweb08
 
justin presentation upload PPT june 25 ADVANCED
justin presentation upload PPT june 25 ADVANCEDjustin presentation upload PPT june 25 ADVANCED
justin presentation upload PPT june 25 ADVANCEDtechweb08
 
justin presentation slideshare1
justin presentation slideshare1justin presentation slideshare1
justin presentation slideshare1techweb08
 

Similar to Unit testing and test driven development using vs (20)

Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
12 Rational Solo Pruebas 2009
12 Rational Solo Pruebas 200912 Rational Solo Pruebas 2009
12 Rational Solo Pruebas 2009
 
Paper CS
Paper CSPaper CS
Paper CS
 
alkatest7
alkatest7alkatest7
alkatest7
 
justin presentation upload PPT june 19
justin presentation upload PPT june 19justin presentation upload PPT june 19
justin presentation upload PPT june 19
 
justin for ppt1 by browse button
justin for ppt1 by browse buttonjustin for ppt1 by browse button
justin for ppt1 by browse button
 
Paper Ps
Paper PsPaper Ps
Paper Ps
 
upload ppt by browse button
upload ppt by browse buttonupload ppt by browse button
upload ppt by browse button
 
justin presentation Slideshare PPT upload June 25 Final one
justin presentation Slideshare PPT upload June 25 Final onejustin presentation Slideshare PPT upload June 25 Final one
justin presentation Slideshare PPT upload June 25 Final one
 
Paper Ps
Paper PsPaper Ps
Paper Ps
 
upload ppt1 by browse button
upload ppt1 by browse buttonupload ppt1 by browse button
upload ppt1 by browse button
 
Paper Ps
Paper PsPaper Ps
Paper Ps
 
Paper Ps
Paper PsPaper Ps
Paper Ps
 
upload ppt by browse button
upload ppt by browse buttonupload ppt by browse button
upload ppt by browse button
 
Justin Presentation PPT Upload June 25 adv
Justin Presentation PPT Upload June 25 advJustin Presentation PPT Upload June 25 adv
Justin Presentation PPT Upload June 25 adv
 
justin presentation upload PPT june 25 ADVANCED
justin presentation upload PPT june 25 ADVANCEDjustin presentation upload PPT june 25 ADVANCED
justin presentation upload PPT june 25 ADVANCED
 
justin presentation slideshare1
justin presentation slideshare1justin presentation slideshare1
justin presentation slideshare1
 

More from Abhimanyu Singhal

Containerization with Microsoft Azure
Containerization with Microsoft AzureContainerization with Microsoft Azure
Containerization with Microsoft AzureAbhimanyu Singhal
 
Azure Functions & Serverless Computing
Azure Functions & Serverless ComputingAzure Functions & Serverless Computing
Azure Functions & Serverless ComputingAbhimanyu Singhal
 
Opportunity: Data, Analytic & Azure
Opportunity: Data, Analytic & Azure Opportunity: Data, Analytic & Azure
Opportunity: Data, Analytic & Azure Abhimanyu Singhal
 
Unit testing with visual studio 2012
Unit testing with visual studio 2012Unit testing with visual studio 2012
Unit testing with visual studio 2012Abhimanyu Singhal
 
Project management with team foundation server 11
Project management with team foundation server 11Project management with team foundation server 11
Project management with team foundation server 11Abhimanyu Singhal
 
Debugging application using visual studio 2010 and intellitrace
Debugging application using visual studio 2010 and intellitraceDebugging application using visual studio 2010 and intellitrace
Debugging application using visual studio 2010 and intellitraceAbhimanyu Singhal
 
Web and load testing with Visual Studio 2010 Ultimate
Web and load testing with Visual Studio 2010 UltimateWeb and load testing with Visual Studio 2010 Ultimate
Web and load testing with Visual Studio 2010 UltimateAbhimanyu Singhal
 
Database development with visual studio 2010
Database development with visual studio 2010Database development with visual studio 2010
Database development with visual studio 2010Abhimanyu Singhal
 

More from Abhimanyu Singhal (15)

ASP.NET Core
ASP.NET CoreASP.NET Core
ASP.NET Core
 
Containerization with Microsoft Azure
Containerization with Microsoft AzureContainerization with Microsoft Azure
Containerization with Microsoft Azure
 
Azure Functions & Serverless Computing
Azure Functions & Serverless ComputingAzure Functions & Serverless Computing
Azure Functions & Serverless Computing
 
Mobile devops
Mobile devopsMobile devops
Mobile devops
 
Opportunity: Data, Analytic & Azure
Opportunity: Data, Analytic & Azure Opportunity: Data, Analytic & Azure
Opportunity: Data, Analytic & Azure
 
Using Specflow for BDD
Using Specflow for BDDUsing Specflow for BDD
Using Specflow for BDD
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
 
Unit testing with visual studio 2012
Unit testing with visual studio 2012Unit testing with visual studio 2012
Unit testing with visual studio 2012
 
Exploratory testing
Exploratory testingExploratory testing
Exploratory testing
 
Project management with team foundation server 11
Project management with team foundation server 11Project management with team foundation server 11
Project management with team foundation server 11
 
Coded ui test
Coded ui testCoded ui test
Coded ui test
 
Visual Studio ALM
Visual Studio ALMVisual Studio ALM
Visual Studio ALM
 
Debugging application using visual studio 2010 and intellitrace
Debugging application using visual studio 2010 and intellitraceDebugging application using visual studio 2010 and intellitrace
Debugging application using visual studio 2010 and intellitrace
 
Web and load testing with Visual Studio 2010 Ultimate
Web and load testing with Visual Studio 2010 UltimateWeb and load testing with Visual Studio 2010 Ultimate
Web and load testing with Visual Studio 2010 Ultimate
 
Database development with visual studio 2010
Database development with visual studio 2010Database development with visual studio 2010
Database development with visual studio 2010
 

Unit testing and test driven development using vs

  • 1. Effective Test Driven Development & Unit Testing with Visual Studio 2010 Abhimanyu Singhal Lead Consultant iMentor Knowledge Services
  • 2. About Me History First Laid Hands on Computers in 1994 – Been a Geek for Quite Some time Worked on different platforms and technologies Career Focus – Embedded Systems and Native Development Currently Help companies use Visual Studio Team System as an ALM Platform High-End Technical Consultancy and Training
  • 4. Why is TDD Good Thinking about tests pushes developer to understand better the gathered requirements Reduces the over engineered code (dead code) Unit Tests help to check that any new modification wont break the existing features. TDD increases software flexibility TDD code is more decoupled
  • 5.
  • 6. Demo – TDD for a Stack
  • 7. Visual Studio Team Test A Visual Studio integrated unit-testing framework Code generation of test method stubs. Running tests within the IDE. Incorporation of test data loaded from a database. Code coverage analysis once the tests have run.
  • 8. TestMethodAttribute Class Designates a Method as a Test Method Found in Microsoft.VisualStudio.QualityTools.UnitTesting.Framework Namespace TestMethod has to be an instance method with no paramters Method name is irrelevant because reflection searches for TestMethod Attribute
  • 9.
  • 10.
  • 11. ExpectedException Attribute Takes a Parameter which is Exception Type to watch for If Exception does not occur test fails The Second parameter (string) is optional is the error message displayed when exception is not thrown
  • 12. Loading Test Data From Database Use Test Properties Window Add TestData Attribute Source Type Connection String TableName DataAccessMethod
  • 13. The TestContext Provides associated data through DataRow Property TestDirectory, TestName Mesuring Test Time using BeingTimer() EndTimer()
  • 14. Code Coverage Determines how much code is tested Shows Percentage of Code Executed Highlights code to show which lines are executed
  • 15. Initializing and Cleaning Up Tests TestInitialize Attribute TestCleanup Attribute Code to be run before and after each test method Other Attributes for Lifetime Methods AssemblyInitializeAttribute/AssemblyCleanupAttribute ClassInitializeAttribute/ClassCleanupAttribute.
  • 17. Guidance – Unit Testing Keep Testing Code in Separate Assemblies Check for cleanup during test setup and execute the cleanup prior to the setup as necessary Avoid creating dependencies between tests, each test should be autonomous. Create one test class corresponding to each class within the production code. Avoid creating other machine dependent tests Create mock objects to test interfaces
  • 19. Thank You abhimanyu@imentor.co.in @abhi_singhal http://www.imentor.co.in/blog