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"];