test-driven development with visual studio 2005 erno de weerd [email protected] info support

23
Test-Driven Development With Visual Studio 2005 Erno de Weerd [email protected] Info Support

Upload: polly-burns

Post on 24-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Test-Driven Development With Visual Studio 2005

Erno de [email protected]

Info Support

Agenda

• What is Test-Driven Development?

• How to do TDD

• TDD and Visual Studio 2005

• What now?

• More Information

• Q&A

What is TDD?

“Test-Driven Development seeks specification, not validation, letting you think through your design before you write your functional code”

- Scott Ambler

“Test-Driven Development is a powerful way to produce well designed code with fewer defects”

- Martin Fowler

What is TDD?

• ‘History’:– The inner loop of Extreme Programming

• TDD is:– A design method (and more)

• TDD is not:– Just writing tests first– A guarantee of quality– Unit testing

What is TDD?

• TDD as a Design Method:– Evolutional– Baby steps– Iterative

What is TDD?

• Evolutional:– No Analysis and Design first– Resilience when requirements are discovered

or change

What is TDD?

• Baby Steps:– One test at the time– Avoid complex code– Code quickly

• Fix the current test

– The majority of invested time should be spend on refactoring

What is TDD?

• Iterative

Update test list

Pick a test

Write the test

Get the code to compile and FAIL

See the test fail

Make the code pass the test

Refactor

Run all tests

How to do TDD

• Updating the Test List– Add small portions of functionality– Add extra test cases– Do not try to make the list complete from the

start– Prioritize the tests

• Risk, ability, …

– Do this during the entire process• Do NOT get sidetracked!

How to do TDD

• Pick a Test– Pick the single test on top of the test list

How to do TDD

• Write the Test– Keep the code as clean as possible– Update the test list instead of coding extra

tests

DEMODEMO DEMODEMO

How to do TDD

• Get the Code to Compile and FAIL– Add a method stub that throws an exception

• NotImplementedException

DEMODEMO DEMODEMO

How to do TDD

• See the Test Fail– You want to be sure it fails: Test the test…

DEMODEMO DEMODEMO

How to do TDD

• Make the Code Pass the Test– Don’t worry too much about ‘clean’ code

• Get the work done

• Do NOT add code that is not being tested

• Do NOT use too many stubs/mockups

DEMODEMO DEMODEMO

How to do TDD

• Refactor– Cleaning up– Remodeling without changing external

behavior• This is where the Unit Tests prove their use

– Allows easy addition of new code – Breaking down large methods/classes– Removing duplicates– Reordering code DEMODEMO DEMODEMO

How to do TDD

• Run All Tests– Making sure you didn’t break the solution– Theoretically: Always run all tests

• This might take to long always run all tests when making a daily build

DEMODEMO DEMODEMO

TDD and Visual Studio 2005

• From the Demo:– Unit Testing

• Generating stubs• Generating tests• Debugging

– Coverage checking– Refactoring

TDD and Visual Studio 2005

• Visual Studio Also Allows:– ‘GUI’ testing– Load testing (Web Applications)– Performance monitoring

• Team System Allows to:– keep track of work items– keep track of progress– force the tests to run successfully before

enabling to check-in the code

TDD and Visual Studio 2005

• Visual Studio 2005 Delivers the Tools– It does NOT force you to use them– They can be used in ANY kind of software

development process (MSF, RUP, XP, …)

What now?

• Developers:– Learn to Refactor– Learn Unit Testing– Learn Whidbey

• Technical Project Leaders:– Learn/adopt a Software Development Method– Learn Visual Studio Team System/Foundation

Server

More Information

• http://www.infosupport.com

• http://msdn.microsoft.com

• http://www.testdriven.com

• “Refactoring: Improving the Design of Existing Code” - Martin Fowler

More Information

• MSDN Fast Track– http://www.microsoft.nl/msdnfasttrack– Technical Seminars (1 day) &

Technical Training (3-5 days)• SQL Server Database Development• Visual Studio Team System• SQL Server Business Intelligence• Smart Client Development• Web Development

Q&A