jer*_*enh 6 .net mstest assemblies app-config
我需要在单元测试中从appsettings部分(在app.config中定义)中读取设置.我们在这个项目中使用mstest.
说这是app.config:
<configuration>
<appSettings>
<add key="MyAppSetting" value="MyAppSettingValue"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这是相应的测试,它通过了这个设置:
[TestClass]
public class ConfigurationTests
{
[TestMethod]
public void can_read_appsettings()
{
string value = ConfigurationManager.AppSettings.Get("MyAppSetting");
Assert.AreEqual("MyAppSettingValue", value);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试将appSettings部分移动到custom.config文件时,此测试失败.
这就是我的app.config文件现在的样子:
<configuration>
<appSettings file='Custom.config' />
</configuration>
Run Code Online (Sandbox Code Playgroud)
我将Custom.config文件添加到我的项目中(使用构建操作'始终复制'):
<appSettings>
<add key="MyAppSetting" value="MyAppSettingValue"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
在控制台应用程序中执行相同操作时,这是有效的.有没有办法在单元测试装配中使这个工作?
| 归档时间: |
|
| 查看次数: |
7303 次 |
| 最近记录: |