【问题标题】:AKKA.NET configuration in a unittest context单元测试上下文中的 AKKA.NET 配置
【发布时间】:2016-08-25 18:56:39
【问题描述】:

我正在尝试在 .NET Core 1.0 的单元测试上下文中使用 HOCON 配置块配置我的 AKKA.NET 运行时环境。显然配置不是从 App.config 文件中提取的。

谁能解释 AKKA.NET 在单元测试上下文 (xunit) 中运行时如何获取 HOCON 配置?

如果上述问题没有提供足够的信息,这里有一些详细信息:

我试图避免众所周知的警告。

NewtonSoftJsonSerializer has been detected as a default serializer. It will be obsoleted in Akka.NET starting from version 1.5 in the favor of Wire 

我设法通过 App.config 中的以下部分使用 AKKA.NET 从控制台应用程序中删除此消息:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="akka" type="Akka.Configuration.Hocon.AkkaConfigurationSection, Akka" />
  </configSections>
  <akka>
    <hocon>
    <![CDATA[
        akka {
                actor {
                    serializers {
                      wire = "Akka.Serialization.WireSerializer, Akka.Serialization.Wire"
                    }
                        serialization-bindings {
                        "System.Object" = wire
                        }
                    }
                }
    ]]>
    </hocon>
  </akka>
</configuration>

当我在我的 unittest 项目中执行相同操作时,它不会产生相同的效果。

我正在使用 xunit 进行单元测试。这些是我的依赖项:

"Akka": "1.1.1",
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0",
"NSubstitute": "1.10.0",
"xunit": "2.2.0-beta2-build3300",
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"Akka.TestKit": "1.1.1",
"Akka.TestKit.Xunit2": "1.1.1",
"Akka.Serialization.Wire": "1.1.1.28-beta"

【问题讨论】:

  • 您的测试项目中是否有相同的配置文件?
  • 是的,我在我的 unittest 项目中添加了相同的 App.config。

标签: unit-testing .net-core akka.net


【解决方案1】:

原来是构建问题。 App.config 文件被复制到构建文件夹(类似于 .\bin\Debug\net46\win7-x64),这个副本有时是陈旧的,这意味着它没有正确更新。在构建之前删除 bin 文件夹解决了这个问题。

【讨论】:

    猜你喜欢
    • 2017-03-07
    • 1970-01-01
    • 2014-10-26
    • 2015-08-30
    • 1970-01-01
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多