Use the config file to read tester-related variables in the test.

Source: Internet
Author: User

 

In Unit Tests, you sometimes need to read variable related to the test operator,
For example, the directory structure of different test machines is different. A test directory of test machine A is C: \ ABC, and the directory of test machine B is D: \ XYZ \ ABC, hard encoding affects the portability of the test.

Solution:
1. store the information in app. config of TestProject, for example:

<Deleetaskfile = "user. config">
<Add key = "WebServerPhysicalPath" value = "C: \ WebRoot"/>
<Add key = "WebSiteUrl" value = "http: // localhost: 8888/>
</AppSettings>

 

Note:: File = "user. config"

 

2. Input similar content in user. config of another file. You can configure your own variable. user. config in this file without putting it on SVN.

<Deleetask>
<Add key = "WebServerPhysicalPath" value = "D: \ UserJack \ WebRoot"/>
</AppSettings>

 

3. add a TestRunConfig in Solution. testrunconfig, double-click the Deployment page, and add user. config file. in this way, each test run, user. config will be copied to the test directory (similar to TestResults \ Jack 2010-02-03 22_26_58 \ Out ).

 

4. Access the configuration variable in the test program:
String webRootPath = System. Configuration. ConfigurationSettings. receivettings ["WebServerPhysicalPath"];

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.