Chapter 7. Test-Driven Development

WHAT YOU WILL LEARN IN THIS CHAPTER

  • What is test-driven development?

  • Why should you test your applications?

  • How to create unit tests in Visual Studio

  • How to run automated tests in Visual Studio

  • Testing in database applications

  • How to create your classes from your tests

  • Testing functionality in various editions of Visual Studio

  • Third-party testing tools

Traditionally, testing has often been an afterthought in software development. Frequently, it was done at — or near — the end of the development cycle. In addition, it was typically the "junior developers" who were tasked with going through the application, testing everything. As a result of these two circumstances, testing often was rushed, incomplete, and led to the release of buggy software to the end users.

Into this mix, a number of developers began to use a new method that became known as test-driven development (TDD). In TDD, you write the tests early (or before you write any real code), and test throughout the development cycle. This means that the code is tested more thoroughly, and by the developers themselves. The result should be fewer bugs, and code that works more closely to the design. It is this last point that causes many TDD proponents to describe TDD not as a testing strategy, but as a design strategy. By writing the tests first, you essentially encapsulate the desired behavior into the tests, meaning the code will follow.

One classic rationale of using this technique was that catching a ...

Get Professional Visual Basic® 2010 and .NET 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.