【发布时间】:2014-10-13 23:21:04
【问题描述】:
我正在编写一些单元测试,这个单元测试确实使用外部库中的代码,这个库希望配置文件包含一些信息。我知道要在我的 UnitTest 中使用App.config,我需要用[DeploymentItem("App.config")] 标记我的TestMethod,但据我所知,这将默认在<appSettings> 部分中查找配置标签。如何指定我的 App.config 是否定义了自定义配置部分?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MySettingSection" type="System.Configuration.AppSettingsSection" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<MySettingSection>
<add key="ApplicationName" value="My Test Application" />
</MySettingSection>
</configuration>
【问题讨论】:
-
你使用的是哪个单元测试框架?
-
@Liath 如果 OP 说了一些关于
DeploymentItemAttribute的话就足以理解 OP 正在谈论 MSTest :D -
@MatíasFidemraizer 感谢您的澄清 - 只有您使用过 MS 框架才能了解它。
-
@Liath 没问题。无论如何,我已经重新标记了这个问题以避免混淆:)
标签: c# unit-testing mstest