【问题标题】:Access config file in nunit在 nunit 中访问配置文件
【发布时间】:2013-08-10 01:31:22
【问题描述】:

我在我的应用程序中使用 nunit。我想访问位于我的测试项目中的配置文件。我通过这个创建了一个虚假的上下文:

  HttpContext.Current = new HttpContext(
               new HttpRequest(null, "http://tempuri.org", null),
               new HttpResponse(null));

我无法通过以下任何方式访问配置文件:

System.Web.Hosting.HostingEnvironment.MapPath("~/MyConfig.config")
HttpContext.Current.Server.MapPath.MapPath("~/MyConfig.config")
System.Web.HttpServerUtility.MapPath("~/MyConfig.config")

【问题讨论】:

    标签: c# asp.net nunit


    【解决方案1】:

    您的配置文件不会部署到您的单元测试中。您可以在测试中添加一个名为 [DeployableItem] 的属性,它将指向您的配置。

    What does `DeploymentItem` attribute mean?

    Xml file not copying to test output directory

    DeploymentItem not deploying files

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-11
      • 1970-01-01
      • 2015-07-19
      • 2014-03-28
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 1970-01-01
      相关资源
      最近更新 更多