Effective Test Driven Development & Unit Testing with Visual Studio 2010<br />Abhimanyu Singhal<br />Lead Consultant<br />...
About Me<br />History<br />First Laid Hands on Computers in 1994 – Been a Geek for Quite Some time<br />Worked on differen...
Objectives<br />
Why is TDD Good<br />Thinking about tests pushes developer to understand better the gathered requirements<br />Reduces the...
Demo – TDD for a Stack<br />
Visual Studio Team Test<br />A Visual Studio integrated unit-testing framework<br />Code generation of test method stubs. ...
TestMethodAttribute Class<br />Designates a Method as a Test Method<br />Found in Microsoft.VisualStudio.QualityTools.Unit...
TestClassAttribute Class<br />Class containing the test method is designated TestClass Attribute<br /><ul><li>Found in Mic...
Team Test Uses Reflection to find Class with TestClass Attribute and Method with TestMethod Attribute and runs it</li></li...
ExpectedException Attribute<br />Takes a Parameter which is Exception Type to watch for<br />If Exception does not occur t...
Loading Test Data From Database<br />Use Test Properties Window<br />Add TestData Attribute<br />Source Type<br />Connecti...
The TestContext<br />Provides associated data through <br />DataRow Property<br />TestDirectory, TestName<br />Mesuring Te...
Code Coverage<br />Determines how much code is tested<br />Shows Percentage of Code Executed<br />Highlights code to show ...
Initializing and Cleaning Up Tests<br />TestInitialize Attribute<br />TestCleanup Attribute<br />Code to be run before and...
The Testing Framework<br />
Guidance – Unit Testing<br />Keep Testing Code in Separate Assemblies<br />Check for cleanup during test setup and execute...
Question and Answers Session<br />
Thank You<br />abhimanyu@imentor.co.in<br />@abhi_singhal<br />http://www.imentor.co.in/blog<br />
iMentor Knowledge Services<br />
Upcoming SlideShare
Loading in...5
×

Unit testing and test driven development using vs

1,163

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,163
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Unit testing and test driven development using vs

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

×