如何阅读的UnitTest项目的App.Config中从试验用HOSTTYPE(QUOT;摩尔") [英] How To Read UnitTest Project's App.Config From Test With HostType("Moles")

查看:209
本文介绍了如何阅读的UnitTest项目的App.Config中从试验用HOSTTYPE(QUOT;摩尔")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下因素测试:

  [TestClass中] 
公共类GeneralTest
{
[TestMethod的]
公共无效VerifyAppDomainHasConfigurationSettings()
{
字符串值= ConfigurationManager.AppSettings [TestValue];
Assert.IsFalse(String.IsNullOrEmpty(值),没有找到App.Config中。);
}

[TestMethod的]
[HOSTTYPE(痣)]
公共无效VerifyAppDomainHasConfigurationSettingsMoles()
{
字符串值= ConfigurationManager中.AppSettings [TestValue];
Assert.IsFalse(String.IsNullOrEmpty(值),没有找到App.Config中。);
}
}



它们之间唯一的区别是 [HOSTTYPE(痣)] 。但是第一次传球和第二个失败。我怎样才能从第二测试读取的App.config?



或可能是我可以在其他地方添加一些其他的配置文件?


< DIV CLASS =h2_lin>解决方案

请参阅的 http://social.msdn.microsoft.com/Forums/en/pex/thread/9b4b9ec5-582c-41e8-8b9c-1bb9457ba3f6



与此同时,作为变通,你可以尝试添加配置设置来Microsoft.Moles.VsHost.x86.exe.config


I have the folowing tests:

[TestClass]
public class GeneralTest
{
    [TestMethod]
    public void VerifyAppDomainHasConfigurationSettings()
    {
        string value = ConfigurationManager.AppSettings["TestValue"];
        Assert.IsFalse(String.IsNullOrEmpty(value), "No App.Config found.");
    }

    [TestMethod]
    [HostType("Moles")]
    public void VerifyAppDomainHasConfigurationSettingsMoles()
    {
        string value = ConfigurationManager.AppSettings["TestValue"];
        Assert.IsFalse(String.IsNullOrEmpty(value), "No App.Config found.");
    }
}

The only difference between them is [HostType("Moles")]. But the first passes and the second fails. How can I read App.config from the second test?

Or may be I can add some another config file in other place?

解决方案

See http://social.msdn.microsoft.com/Forums/en/pex/thread/9b4b9ec5-582c-41e8-8b9c-1bb9457ba3f6

In the mean time, as a work around, you could try adding the configuration settings to Microsoft.Moles.VsHost.x86.exe.config

这篇关于如何阅读的UnitTest项目的App.Config中从试验用HOSTTYPE(QUOT;摩尔&QUOT;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆