Introducing Test-Driven Development

Test-Driven Development (also known as TDD or Test-Driven Design) is a programming approach in which developers create applications by first writing unit tests and then writing the actual code after the unit test passes. This particular approach helps writing better code, because you ensure that it will work via unit tests, but it is also a life philosophy so that you need to have a change of mind when approaching TDD. Basically TDD is structured into three main moments:

Red: The developer generates a new unit test from scratch, so that it will typically fail. This is the reason why it’s called Red.

Green: The developer focuses on writing code that makes the unit test work and pass. As you saw in the previous section, passing unit tests return a green result.

Refactor: This is the moment in which the developer reorganizes code, moving it from the unit test to the actual code system in the application project, making the code clearer and fixing it where necessary.

This chapter is not intended to be a deep discussion on TDD, whereas it is instead intended to be a guide to Visual Studio 2010 instrumentation for Test-Driven Development. Particularly you see how the Generate from Usage new feature discussed in Chapter 18, “‘Generate from Usage’ Coding Techniques,” is the main help you have in TDD with Visual Basic 2010. Before going on, it is a good idea to enable test options that enable double-clicking a test result failure in the Test Results dialog to be redirected to the code that threw errors. Follow these steps:

1. Go to Tools, Options and select the Test Tools, Test Execution subfolder.

2. Enable the Double Clicking Failed or Inconclusive Unit Test Result Displays the Point of Failure in Test item. Figure 59.10 shows how to accomplish this.

Figure 59.10 Setting test execution options.

image

3. Click OK to close the dialog.

At this point you can create a test project where you can launch your unit tests.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.163.207