C# 在MSTest(testConfig)中使用配置文件
我正在尝试在MSTest中使用MyProject.config。我在“部署”(testConfig)中添加了这个文件。 访问这些字段的最佳做法是什么?我可以构建类似Java属性的东西吗 例如:C# 在MSTest(testConfig)中使用配置文件,c#,unit-testing,testing,mstest,configuration-files,C#,Unit Testing,Testing,Mstest,Configuration Files,我正在尝试在MSTest中使用MyProject.config。我在“部署”(testConfig)中添加了这个文件。 访问这些字段的最佳做法是什么?我可以构建类似Java属性的东西吗 例如: <host>localhost</host> <port>0</port> <user>me</user> localhost 0 我 编辑: 我有两个单元测试套件。我想在每个测试中使用不同的配置文件。是任何使用的属性吗?尝试一下
<host>localhost</host>
<port>0</port>
<user>me</user>
localhost
0
我
编辑:
我有两个单元测试套件。我想在每个测试中使用不同的配置文件。是任何使用的属性吗?尝试一下,看看它是否有效,如下所示:
string port = System.Configuration.ConfigurationManager.AppSettings("port");
<configuration>
<appSettings>
<add key="port" value="80" />
</appSettings>
</configuration>
您需要将配置文件重构为标准的“App.config”文件,并添加如下键/值对:
string port = System.Configuration.ConfigurationManager.AppSettings("port");
<configuration>
<appSettings>
<add key="port" value="80" />
</appSettings>
</configuration>
我知道我可以使用App.config。我在询问何时需要使用testconfig。