微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

依赖于文件的.net核心asp.net单元测试 – appsettings.json – 在travis中失败

我创建了一个asp.net点网核心rtm(1.0.0-preview2-003121).

它使用ConfigurationBuilder从appsettings.json生成配置:

public Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json",optional: false,reloadOnChange: true);

    Configuration = builder.Build();
}

我也试过’.SetBasePath(Directory.GetCurrentDirectory())`

现在我的单元测试(在另一个项目中)我正在构建一个内存主机:
我试过了:

_server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
_client = _server.CreateClient();

我试过了:

_server = new TestServer(
        new WebHostBuilder()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseStartup<Startup>());
_client = _server.CreateClient();

我的Travis.yml文件很标准:

install:
# Install .net using linux CLI commands
  - sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
  - sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
  - sudo apt-get update
  - sudo apt-get -qq install dotnet-dev-1.0.0-preview2-003121
  - sudo apt-get install dotnet-hostfxr-1.0.2

script:
  - dotnet restore
  - dotnet build src/Speakr.WebApp.Site
  - dotnet build tests/Speakr.WebApp.Site.Tests
  - dotnet test tests/Speakr.WebApp.Site.Tests -f netcoreapp1.0

在本地,所有工作和建设.在Windows和Ubuntu上.
在travis CI tho,我收到以下错误
错误:Speakr.WebApp.Site.Tests.InMemoryTests.HomeControllerIndexShouldNotBeNull

有没有人见过这个?
我已经尝试将project.json添加到测试项目中,在主项目中包含copyToOutput并在测试项目中包含copytoOutput.

纳达!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐