Udostępnij za pośrednictwem


How to: Configure Tests with Build Definitions

This topic explains how you can modify build definitions and projects in order to use the testing capabilities of Team Foundation Build. The following test types are covered in this topic:

  • ASP.NET unit tests

  • Web service unit tests

  • Web tests

  • Load tests

  • Ordered test

  • Generic tests

Visual Studio Team System Test Edition must be installed on the build computer before you can run tests during build. To confirm that Visual Studio Team System Test Edition is installed, look for it in the Installed products list in the About Microsoft Visual Studio dialog box.

Important noteImportant Note:

   In the Service Pack 1 edition of Team Foundation Server 2008, you can publish test results from two different build definitions with duplicate build numbers. Prior to the Service Pack 1 edition of Team Foundation Server 2008, an attempt to publish test results from two build definitions with the same build number resulted in an error.

To configure tests, complete one or more of the following procedures:

Requirements for Building Web Projects

ASP.NET Unit Tests

Web Service Unit Tests

Web Tests

Load Testing

Ordered Testing

Generic Testing

Required Permissions

To perform these procedures, you must have the Team Foundation Administrators security permission set to Allow. For more information, see Team Foundation Server Permissions.

Requirements for Building Web Projects

To build a Web project by using Team Foundation Build, it must be configured to enable updates.

To configure the Web project so that it can enable updates

  1. In Solution Explorer, select the Web project.

  2. On the View menu, click Property Pages.

  3. In the left pane, click MSBuild Options.

  4. Select Allow this precompiled site to be updatable.

    Note

    By default, this option is already selected.

ASP.NET Unit Tests

ASP.NET projects can be tested in the following ways:

To test ASP.NET projects in IIS

  1. Create an ASP.NET project.

  2. Open the .sln file in a text editor, such as Notepad.

    Note

    By default, the .sln file of an ASP.NET project is located in My Documents\Visual Studio 2008\projects\WebSiteName.

  3. Set the Debug.AspNetCompiler.PhysicalPath and Release.AspNetCompiler.PhysicalPath values equal to "..\SolutionName\WebProjectName".

  4. Create a unit test for the project.

    For more information, see ASP.NET Unit Tests.

  5. Check in the Web project and test project.

  6. Create a new build definition and select the test to run during the build.

    For more information, see How to: Create a Build Definition.

    Note

    In the Select configurations to build step of the MSBuild Project File Creation Wizard, you must type Mixed Platform in the Platform text box for the Web project to build and the test to run successfully. The MSBuild Project File Creation Wizard runs when you choose to create a new project file in the Build Definition dialog box. For more information, see How to: Create a Build Definition.

  7. Manually publish the Web site on the build agent.

  8. Run the build definition.

To test ASP.NET projects on an ASP.NET Development Server

  1. Create an ASP.NET project.

  2. Open the .sln file in a text editor, such as Notepad.

    Note

    By default, the .sln file of an ASP.NET project is located in My Documents\Visual Studio 2008\projects\WebSiteName.

  3. Set the Debug.AspNetCompiler.PhysicalPath and Release.AspNetCompiler.PhysicalPath values equal to "..\SolutionName\WebProjectName".

  4. Create a unit test for the project.

    For more information, see ASP.NET Unit Tests.

  5. Change the path of the AspNetDevelopmentServerHost attribute in the test method to %PathToWebRoot%.

  6. Check in the Web project and test project.

  7. Create a new build definition and select the test to run during the build.

    For more information, see How to: Create a Build Definition.

    Note

    In the Select configurations to build step of the MSBuild Project File Creation Wizard, you must type Mixed Platform in the Platform box for the Web project to build and the test to run successfully. The MSBuild Project File Creation Wizard runs when you choose to create a new project file in the Build Definition dialog box. For more information, see How to: Create a Build Definition.

  8. Run the build definition.

Web Service Unit Tests

Web services can be tested in the following ways:

To test Web services in IIS

  1. Create a Web service project.

    For more information, see Walkthrough: Creating a Web Service Using Visual Basic or Visual C#.

  2. Open the .sln file in a text editor, such as Notepad.

    Note

    By default, the .sln file of an ASP.NET project is located in My Documents\Visual Studio 2008\projects\WebSiteName.

  3. Set the Debug.AspNetCompiler.PhysicalPath and Release.AspNetCompiler.PhysicalPath values equal to "..\SolutionName\WebProjectName".

  4. Create a unit test for the project.

    For more information, see ASP.NET Unit Tests.

  5. Add the following code to the test method, where WebServiceObject is the Web service object, and Location is the location of the Web service.

    WebServiceObject.URL = "Location";
    
  6. Check in the Web project and test project.

  7. Create a new build definition and select the test to run during the build.

    For more information, see How to: Create a Build Definition.

    Note

    In the Select configurations to build step of the MSBuild Project File Creation Wizard, you must type Mixed Platform in the Platform box for the Web project to build and the test to run successfully. The MSBuild Project File Creation Wizard runs when you choose to create a new project file in the Build Definition dialog box. For more information, see How to: Create a Build Definition.

  8. Run the build definition.

To test Web services on an ASP.NET Development Server

  1. Create a Web service project.

    For more information, see Walkthrough: Creating a Web Service Using Visual Basic or Visual C#.

  2. Open the .sln file in a text editor, such as Notepad.

    Note

    By default, the .sln file of an ASP.NET project is located in My Documents\Visual Studio 2008\projects\WebSiteName.

  3. Set the Debug.AspNetCompiler.PhysicalPath and Release.AspNetCompiler.PhysicalPath values equal to "..\SolutionName\WebProjectName".

  4. Create a unit test for the project.

    For more information, see How to: Create and Run a Unit Test.

  5. Include the Microsoft.VisualStudio.QualityTools.UnitTesting.Web namespace in the test class.

  6. Add the AspNetDevelopmentServerAttribute attribute to the unit test.

    For more information, see Unit Tests for ASP.NET Web Services.

  7. Add a call to the TryUrlRedirection method.

    For more information, see the "Using the TryUrlRedirection Method" section in Unit Tests for ASP.NET Web Services.

  8. Check in the Web service and test project.

  9. Create a new build definition and select the test to run during the build.

    For more information, see How to: Create a Build Definition.

    Note

    In the Select configurations to build step of the MSBuild Project File Creation Wizard, you must type Mixed Platform in the Platform box for the Web project to build and the test to run successfully. The MSBuild Project File Creation Wizard runs when you choose to create a new project file in the Build Definition dialog box. For more information, see How to: Create a Build Definition.

  10. Manually publish the Web site on the build agent.

  11. Run the build definition.

Web Tests

To run Web tests with Team Foundation Build, the Visual Studio Team Foundation Build service must be running under the Administrator account on the build computer. For more information about how to install Team Foundation Build, see How to: Set up and Install Team Foundation Build.

Web tests can be run in the following ways:

For more information about Web tests, see Working with Web Tests.

To run Web tests on IIS

  1. Create a Web project.

  2. Open the .sln file in a text editor, such as Notepad.

    Note

    By default, the .sln file of an ASP.NET project is located in My Documents\Visual Studio 2008\projects\WebSiteName.

  3. Create a new Web test.

  4. Check in the Web project and test project.

  5. Create a new build definition and select the test to run during the build.

    For more information, see How to: Create a Build Definition.

    Note

    In the Select configurations to build step of the MSBuild Project File Creation Wizard, you must type Mixed Platform in the Platform box for the Web project to build and the test to run successfully. The MSBuild Project File Creation Wizard runs when you choose to create a new project file in the Build Definition dialog box. For more information, see How to: Create a Build Definition.

  6. Manually publish the Web site on the build agent.

  7. Run the build definition.

To run Web tests on an ASP.NET Development Server

  1. Create a Web project.

  2. Open the .sln file in a text editor, such as Notepad.

    Note

    By default, the .sln file of an ASP.NET project is located in My Documents\Visual Studio 2008\projects\WebSiteName.

  3. Set the Debug.AspNetCompiler.PhysicalPath and Release.AspNetCompiler.PhysicalPath values equal to "..\SolutionName\WebProjectName".

  4. Create a Web test.

    For more information, see Creating a Web Test.

  5. In Solution Explorer, right-click the .webtest file, and then click Open.

  6. Click the Parameterize Web Server button.

  7. Select the Web Server to parameterize, and then click Change.

  8. Select Use ASP.NET Development Server.

  9. In the Path to Web site box, type %PathToWebRoot%\WebSiteProjectName.

  10. In the Web application root box, enter the Web application root.

  11. Click OK, and then click OK again.

  12. Check in the Web service and test project.

  13. Create a new build definition and select the test to run during the build.

    For more information, see How to: Create a Build Definition.

    Note

    In the Select configurations to build step of the MSBuild Project File Creation Wizard, you must type Mixed Platform in the Platform box for the Web project to build and test to run successfully. The MSBuild Project File Creation Wizard runs when you choose to create a new project file in the Build Definition dialog box. For more information, see How to: Create a Build Definition.

  14. Run the build definition.

Load Testing

For more information about load testing, see Working with Load Tests.

To configure a load test for use with Team Foundation Build

  1. Create a load test.

    For more information, see Creating Load Tests.

  2. Be sure that SQL Server Express is installed on the build agent and that the Visual Studio Team Foundation Build service has permission to write to SQL Server Express.

  3. Create a new build definition and select the test to run during the build.

    For more information, see How to: Create a Build Definition.

  4. Run the build definition.

    Note

    To view test results for the load test, you might have to change some configuration settings if the load test repository was on a SQL Server Express setup. If this is the case, enable Remote Connections for SQL Server Express on the build computer.

Ordered Testing

For more information about ordered tests, see Working with Ordered Tests.

To configure a ordered test for use with Team Foundation Build

  1. Create an ordered test.

    For more information, see How to: Create an Ordered Test.

  2. Create a new build definition and select the test to run during the build.

    For more information, see How to: Create a Build Definition.

  3. Run the build definition.

Generic Testing

For more information about generic tests, see Working with Generic Tests.

To configure a generic test for use with Team Foundation Build

  1. Create a generic test.

    For more information, see How to: Create a Generic Test.

  2. Create a new build definition and select the test to run during the build.

    For more information, see How to: Create a Build Definition.

  3. Run the build definition.

See Also

Other Resources

Working with Build Definitions in Team Foundation Build

Test Types

Testing Web Sites and Web Services in a Team Environment