Udostępnij za pośrednictwem


How to: Parameterize a Web Server

You can parameterize the URL for your Web server. The purpose of parameterization is to make it easy to change the Web server that your tests target. A test, either recorded or coded, can run against various servers. When you use parameterization, you can easily change servers by re-mapping the Web server context parameter to another server. You do not have to re-record or re-write the test.

This is useful when, for example, you want to run 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 have Web tests 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. 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 Servers button.

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

    The Change Web Server dialog box appears.

  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=http://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

Concepts

Unit Tests for ASP.NET Web Services

Web Servers in Visual Web Developer