nunit test 中的 app.config 用于验收测试

发布于 2024-11-06 21:50:38 字数 2113 浏览 0 评论 0原文

我写了一些specflow测试。为了运行这些测试,我需要在 App.config 中配置一些部分。在 Visual Studio 中使用 resharper 作为测试运行程序运行测试,它工作得很好,但是当使用 NUnit 测试运行程序运行测试时,似乎没有读取 App.config 并且依赖于它的所有测试都会失败(在我的情况下是每次测试)。

是否可以让 NUnit 测试运行程序读取为 .dll 指定的 app.config?

更新:我正在使用 NUnit 2.5.10 版本。

我的应用程序配置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityMappingsConfiguration" type="OPF.KP.Business.EntitySettings, OPF.KP.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
  </configSections>
  <entityMappingsConfiguration>
    <entityMappings>
      <entityMapping entityShortTypeName="ValidationResult" entityFactoryFullTypeName="OPF.KP.Business.Tests.ValidationResultStubFactory, OPF.KP.Business.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      <entityMapping entityShortTypeName="Stillingsmelding" entityFactoryFullTypeName="OPF.KP.Business.FitNesseTests.StillingsmeldingFitNesseStubFactory, OPF.KP.Business.FitNesseTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      <entityMapping entityShortTypeName="Stillingsmeldingsfelter" entityFactoryFullTypeName="OPF.KP.Business.StillingsmeldingsfelterFactory, OPF.KP.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      <entityMapping entityShortTypeName="IInputModeSettings" entityFactoryFullTypeName="OPF.KP.Business.Tests.SettingsStubFactory, OPF.KP.Business.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </entityMappings>
  </entityMappingsConfiguration>
  <appSettings>
    <add key="ShouldExecuteHistoricValidation" value="true" />
    <add key="Kontrollstasjon.ValidatorService.Validate.ExecuteNoEnhetDuplicationVerification" value="false" />
  </appSettings>
  <specFlow>
    <language feature="no" />
  </specFlow>
</configuration>

I have written some specflow tests. To get those test to run I need to configure some parts in App.config. Running the test with resharper as test runner in visual studio it works perfectly fine, but when running the test with the NUnit test runner it seems like the App.config is not read and all tests that depends on it fails (in my case that is every test).

Is there possible to get the NUnit test runner to read the app.config specified for a .dll?

UPDATE: I'm using the 2.5.10 version of NUnit.

My app.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityMappingsConfiguration" type="OPF.KP.Business.EntitySettings, OPF.KP.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
  </configSections>
  <entityMappingsConfiguration>
    <entityMappings>
      <entityMapping entityShortTypeName="ValidationResult" entityFactoryFullTypeName="OPF.KP.Business.Tests.ValidationResultStubFactory, OPF.KP.Business.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      <entityMapping entityShortTypeName="Stillingsmelding" entityFactoryFullTypeName="OPF.KP.Business.FitNesseTests.StillingsmeldingFitNesseStubFactory, OPF.KP.Business.FitNesseTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      <entityMapping entityShortTypeName="Stillingsmeldingsfelter" entityFactoryFullTypeName="OPF.KP.Business.StillingsmeldingsfelterFactory, OPF.KP.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      <entityMapping entityShortTypeName="IInputModeSettings" entityFactoryFullTypeName="OPF.KP.Business.Tests.SettingsStubFactory, OPF.KP.Business.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </entityMappings>
  </entityMappingsConfiguration>
  <appSettings>
    <add key="ShouldExecuteHistoricValidation" value="true" />
    <add key="Kontrollstasjon.ValidatorService.Validate.ExecuteNoEnhetDuplicationVerification" value="false" />
  </appSettings>
  <specFlow>
    <language feature="no" />
  </specFlow>
</configuration>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文