How to: Parameterize a Web Server

The URL for your Web server can be parameterized, which makes it easy to change the Web server that your tests are targeting. The benefit is that a test, either recorded or coded, can run against another server and only the minor change of mapping the Web server context parameter to another server is required. You do not have to re-record or re-write the test.

This is useful when you want to run your tests on a Web server that has one name in your non-production environment and another name in your production environment. In this case, both the Web servers are active Web servers.

You can also modify Web tests to target the ASP.NET Development Web Server on your local computer. You can create Web services on your local computer that use the ASP.NET Development Server to host your Web application. The ASP.NET Development Server is started and stopped automatically when you run your Web test. For more information about ASP.NET Development Server, see Web Servers in Visual Web Developer.

Additionally, if your test will run on a designated test Web server for build verification, the target Web site can be identified outside the actual Web test. Identifying the Web server outside the test allows you to avoid editing any part of the test that is under source code control.

To create a context parameter for a Web server

  1. Open a Web test.

  2. Click the Parameterize Web Server button.

  3. In the Parameterize Web Server dialog box, select the Web Server you want to parameterize and then click Change.

  4. In the Change Web Server dialog box, type a name for the Context parameter name.

  5. Select either Use Web server or ASP.NET Development Server.

  6. If you choose ASP.NET Development Server, you must indicate the path to the Web site on your local computer and the Web application root.

    Note

    You can parameterize the path to the Web site by using an environment variable, such as Test.WebServer1. For example, from a command line, type set Test.WebServer1=https://MyProductionServer. Then, if you run the Web test from the command line by using MSTest.exe, the environment variable will be in effect for that test run. For more information about running tests from a command line, see How to: Run Tests from the Command Line.

  7. Click OK.

  8. If you have more than one Web server to map, you can select it and repeat the procedure. When you have finished mapping the Web servers to context parameter names, click OK.

    The context parameters are visible in the Web test. You can see the mappings between the context parameter name and the Web server.

    Note

    The ASP.NET Development Servers are started and stopped at the end automatically of the test run.

See Also

Tasks

How to: Create an ASP.NET Unit Test

Concepts

Testing Web Services
Web Servers in Visual Web Developer