ebook img

Visual Studio 2010 Unit Testing PDF

164 Pages·2013·1.75 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Visual Studio 2010 Unit Testing

Testing In Visual Studio 2010 Benjamin Day Copyright © 2013, Benjamin Day Consulting, Inc. www.benday.com 1 Benjamin Day • Consultant, Coach, Trainer • Scrum.org Classes – Professional Scrum Developer (PSD) – Professional Scrum Foundations (PSF) • TechEd, VSLive, DevTeach, O’Reilly OSCON • Visual Studio Magazine, Redmond Developer News • Microsoft MVP for Visual Studio ALM • Team Foundation Server, TDD, Testing Best Practices, Silverlight, Windows Azure • http://blog.benday.com • Agenda • What is Test Driven Development? • How do you do Test Driven Development in VS? • Why Test Driven Development? • How much is enough? • Code Coverage • Code Profiling • Data-driven Tests • Ordered tests • Dynamic Mocks using RhinoMocks • Design for Testability • User Interface Testing Copyright © 2013, Benjamin Day Consulting, Inc. www.benday.com 3 What is Test Driven Development? • Way of developing code so that you always have proof that something is working – Code that validates other code – Small chunks of “is it working?” • Small chunks = Unit Tests • Kent Beck (“Test-Driven Development”, Addison-Wesley) says “Never write a single line of code unless you have a failing automated test.” Copyright © 2013, Benjamin Day Consulting, Inc. www.benday.com 4 What is a Unit Test? • Wikipedia says, “a unit test is a procedure used to validate that a particular module of source code is working properly” • Method that exercises another piece of code and checks results and object state using assertions Copyright © 2013, Benjamin Day Consulting, Inc. www.benday.com 5 How to begin? • Get an idea for what you want to develop • Brainstorm success and failure scenarios – These become your tests Copyright © 2013, Benjamin Day Consulting, Inc. www.benday.com 6 The Process • From William Wake’s “Extreme Programming Explored” (Addison-Wesley) 1. Write the test code 2. Compile the test code  Fails because there’s no implementation 3. Implement just enough to compile 4. Run the test  Fails 5. Implement enough code to make the test pass 6. Run the test  Pass 7. Refactor for clarity and to eliminate duplication 8. Repeat Copyright © 2013, Benjamin Day Consulting, Inc. www.benday.com 7 Structure of a Unit Test • Arrange – Set up the System Under Test (SUT) • Act – Run the operation(s) • Assert – Verify that it worked Copyright © 2013, Benjamin Day Consulting, Inc. www.benday.com 8 SO, HOW DO I DO TDD IN VISUAL STUDIO 2010? Copyright © 2013, Benjamin Day Consulting, Inc. www.benday.com 9 Basic structure of a Visual Studio unit test • Microsoft.VisualStudio.QualityTools.UnitTestFramework • Test fixture (aka Test Class) – Marked with the [TestClass] attribute – Collection of unit test methods – Needs a parameter-less constructor • Unit test method – Marked with the [TestMethod] attribute – Must be public – Must return void – No method parameters Copyright © 2013, Benjamin Day Consulting, Inc. www.benday.com 10

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.