加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

依赖于文件的.net核心asp.net单元测试 – appsettings.json –

发布时间:2020-12-15 20:46:51 所属栏目:asp.Net 来源:网络整理
导读:我创建了一个asp.net点网核心rtm(1.0.0-preview2-003121). 它使用ConfigurationBuilder从appsettings.json生成配置: public Startup(IHostingEnvironment env){ var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile(
我创建了一个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.

纳达!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读