Creating, Configuring, and Managing Tests


Testing is no longer a manual process tracked inside an Excel spreadsheet. Instead, testing is now built into the Visual Studio IDE. Here, you can create test projects and tests. You can control, configure, and manage these tests in a central area. You can also execute tests and publish the results to Team Foundation Server. In the following sections, we'll look at the basics of test projects, test items, and test management.

Test Projects

You define tests inside test projects. This is a familiar paradigm for all Visual Studio users: create a project, add items to that project. In this way, you can group test items under one or more projects. You can also check that project (and associated items) into source control as you would any other project.

In most cases you create a single test project for an application. That is, if your application is contained within a single solution, you would add a test project to that solution. Of course, there are exceptions. For larger projects, you may want to break out the test project by component, module, or even iteration.

Creating a Test Project

You create a test project like any other. You can choose New Project from the File menu, or you can right-click a solution and indicate the same. In either case, you are presented with the New Project dialog box. Figure 22.1 shows an example.

Figure 22.1. Creating a new test project.


From the New Project dialog box, you navigate to Test Projects and then Test Documents. This will allow you to use the Test Project template. Notice that when adding a new test project, you can indicate whether Visual Studio should create a new solution or add your new project to the existing solution.

Configuring the Creation of Test Projects

By default, when you create a new test project, a new manual test and unit test are added to the project. Your project template also gets an automatic reference to the UnitTestFramework namespace. Figure 22.2 shows the Solution Explorer with a new test project highlighted, CustomerManagerTests.

Figure 22.2. A new test project.


The Test Project template is actually configurable. To configure it, you can bring up the Options dialog box (by selecting Tools, Options) and select the Test Project node under Test Tools. Figure 22.3 shows an example.

Figure 22.3. New test project options.


From this Options dialog box, you can indicate the default test project type (C#, VB, and so on). You can also indicate the default items that are added to the test project upon creation. Notice the default settings include a unit test, a manual test, and an introductory file. You can override these settings by selecting the check boxes.

Test Items

A number of test item templates are defined for Visual Studio. Each represents a different test or a version of a test. These items are added to a test project. Each is a file that can be versioned inside source control. Figure 22.4 shows the Add New Test dialog box.

Figure 22.4. The Add New Test dialog box.


The figure shows the full list of the test items available. We will cover each one throughout this chapter. However, Table 22.1 provides a brief overview of each test item.

Table 22.1. Visual Studio Test Items

Test

Description

Generic Test

A generic test is an application or third-party tool that should be treated like a test. The generic test wraps this application.

Load Test

A load test is used to test your application's behavior when many concurrent users are accessing it.

Manual Test (text format)

A manual test is a set of steps that must be performed by a tester. This test is described as text. When the test is run, a tester has to indicate the results of the manual test.

Manual Test (Word format)

A manual test (see above) is written using Microsoft Word.

Ordered Test

An ordered test allows you to execute existing tests in a set order.

Unit Test

A unit test is a bit of code that executes a portion of your application and asserts the results.

Unit Test Wizard

The Unit Test Wizard allows you to automatically generate unit tests for existing code.

Web Test

A web test is used to test your web application. These tests can be recorded and then seeded with data to exercise an entire web user interface.


Test Manager

The larger the project, the more tests you will have. It is not uncommon for a project to have hundreds of tests. Each unit test, web test, load test, or manual test needs to be managed. Thankfully, Visual Studio provides the Test Manager tool to solve this issue. With it, you can organize tests into lists, group tests together, filter which test details you want to view, search for tests, run a group of tests, and more. It is the principal tool for the tester to bring order to his or her work. You access this tool from the Test menu (by selecting Test, Windows, Test Manager) or from the Test Tools toolbar. Figure 22.5 shows the Test Manager window in the IDE.

Figure 22.5. The Test Manager.


Notice the selection to view tests that are not in a list (by default this is all tests) in the tree view on the left. The tests themselves are shown in the list to the right. You can group the test list by namespace, project, test type, and so on using the Group By option on the Test Manager toolbar. This toolbar also allows you to indicate which columns, search for tests, run tests, and so on.

Test Lists

Test lists allow you to choose the grouping of tests in the test case manager. You can define your own custom lists and then add tests to those lists. Perhaps the biggest benefit to test lists is that you can run a list as a single unit. This gives you control over what tests to group together to form, for instance, a module test.

To define a test list, you can right-click the Lists of Tests node on the Test Manager navigation tree view. You can also select Create New Test List from the Test menu. Selecting this menu option brings up the Create New Test List dialog box. Figure 22.6 shows this dialog box in action.

Figure 22.6. The Create New Test List dialog box.


In the Create New Test List dialog box, you define the list name, provide a description, and indicate where the list should exist in the test list hierarchy. Finally, you add tests to the list through drag-and-drop in the IDE.

Tip

A test may exist in one or more lists. This capability can be very helpful. You can reuse tests across lists and then execute that list as a group. For example, you may put a specific unit test in a regression test list you create and then reuse it again in a specific module test.


Testing Configuration

When you create a test project, Visual Studio adds a test configuration file to the solution. This file, with the extension .testrunconfig, can be found under the Solution Items folder. You use this configuration file to set a number of settings related to code coverage, web tests, test setup and cleanup, and so on. An example of the dialog box is shown in Figure 22.7. We will refer back to this configuration as we move through the chapter.

Figure 22.7. Test run configuration.





Microsoft Visual Studio 2005 Unleashed
Microsoft Visual Studio 2005 Unleashed
ISBN: 0672328194
EAN: 2147483647
Year: 2006
Pages: 195

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net