<i id='FuTPO'><tr id='FuTPO'><dt id='FuTPO'><q id='FuTPO'><span id='FuTPO'><b id='FuTPO'><form id='FuTPO'><ins id='FuTPO'></ins><ul id='FuTPO'></ul><sub id='FuTPO'></sub></form><legend id='FuTPO'></legend><bdo id='FuTPO'><pre id='FuTPO'><center id='FuTPO'></center></pre></bdo></b><th id='FuTPO'></th></span></q></dt></tr></i><div id='FuTPO'><tfoot id='FuTPO'></tfoot><dl id='FuTPO'><fieldset id='FuTPO'></fieldset></dl></div>

    <legend id='FuTPO'><style id='FuTPO'><dir id='FuTPO'><q id='FuTPO'></q></dir></style></legend>
      <bdo id='FuTPO'></bdo><ul id='FuTPO'></ul>
    1. <small id='FuTPO'></small><noframes id='FuTPO'>

      <tfoot id='FuTPO'></tfoot>

    2. 使用 .NET Framework 集成测试 ASP.NET Core - 找不到 deps.json

      Integration testing ASP.NET Core with .NET Framework - can#39;t find deps.json(使用 .NET Framework 集成测试 ASP.NET Core - 找不到 deps.json)
        <tbody id='YZ2Rp'></tbody>

        <bdo id='YZ2Rp'></bdo><ul id='YZ2Rp'></ul>
        1. <legend id='YZ2Rp'><style id='YZ2Rp'><dir id='YZ2Rp'><q id='YZ2Rp'></q></dir></style></legend>
            <tfoot id='YZ2Rp'></tfoot>

            <small id='YZ2Rp'></small><noframes id='YZ2Rp'>

            <i id='YZ2Rp'><tr id='YZ2Rp'><dt id='YZ2Rp'><q id='YZ2Rp'><span id='YZ2Rp'><b id='YZ2Rp'><form id='YZ2Rp'><ins id='YZ2Rp'></ins><ul id='YZ2Rp'></ul><sub id='YZ2Rp'></sub></form><legend id='YZ2Rp'></legend><bdo id='YZ2Rp'><pre id='YZ2Rp'><center id='YZ2Rp'></center></pre></bdo></b><th id='YZ2Rp'></th></span></q></dt></tr></i><div id='YZ2Rp'><tfoot id='YZ2Rp'></tfoot><dl id='YZ2Rp'><fieldset id='YZ2Rp'></fieldset></dl></div>

                本文介绍了使用 .NET Framework 集成测试 ASP.NET Core - 找不到 deps.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我有一个面向 .NET Framework 4.7 的 ASP.NET Core Web API 项目,我正在尝试为其编写集成测试.我使用 Visual Studio 添加新项目和单元测试项目 (.NET Framework) 模板创建了一个单元测试项目.我将 Microsoft.AspNetCore.Mvc.Testing NuGet 包添加到测试项目中,我有以下测试:

                I have a ASP.NET Core Web API project targeting .NET Framework 4.7 that I'm trying to write integration tests for. I created a unit test project using Visual Studio Add new project and then the Unit Test Project (.NET Framework) template. I added the Microsoft.AspNetCore.Mvc.Testing NuGet package to the test project, and I have the following test:

                using System.Threading.Tasks;
                using Microsoft.AspNetCore.Mvc.Testing;
                using Microsoft.VisualStudio.TestTools.UnitTesting;
                
                namespace TestRepro.Tests
                {
                    [TestClass]
                    public class UnitTest1
                    {
                        [TestMethod]
                        public async Task TestMethod1()
                        {
                            var factory = new WebApplicationFactory<Startup>();
                            var client = factory.CreateClient();
                            var response = await client.GetAsync("/api/values");
                        }
                    }
                }
                

                但这会引发以下异常:

                测试方法TestRepro.Tests.UnitTest1.TestMethod1抛出异常:System.InvalidOperationException:找不到'[路径已删除]TestRepro.TestsinDebugTestRepro.deps.json'.此文件是功能测试正常运行所必需的.您的源项目 bin 文件夹中应该有该文件的副本.如果不是这种情况,请确保在项目文件中将属性 PreserveCompilationContext 设置为 true.例如真实".要使功能测试正常工作,它们需要从构建输出文件夹运行,或者必须将应用程序输出目录中的 TestRepro.deps.json 文件复制到运行测试的文件夹中.此错误的常见原因是在测试运行时启用了卷影复制.

                Test method TestRepro.Tests.UnitTest1.TestMethod1 threw exception: System.InvalidOperationException: Can't find'[path removed]TestRepro.TestsinDebugTestRepro.deps.json'. This file is required for functional tests to run properly. There should be a copy of the file on your source project bin folder. If that is not the case, make sure that the property PreserveCompilationContext is set to true on your project file. E.g 'true'. For functional tests to work they need to either run from the build output folder or the TestRepro.deps.json file from your application's output directory must be copied to the folder where the tests are running on. A common cause for this error is having shadow copying enabled when the tests run.

                我已验证 Web 应用程序输出文件夹 (TestReproinDebug et47) 中存在 TestRepro.deps.json,但它没有复制到测试项目输出文件夹 (TestRepro.TestsinDebug).而且我还没有找到如何禁用卷影复制.

                I have verified that TestRepro.deps.json exists in the web application output folder (TestReproinDebug et47), but it is not copied to the test project output folder (TestRepro.TestsinDebug). And I have not been able to find out how to disable shadow copying.

                文档说:

                Microsoft.AspNetCore.Mvc.Testing 包处理以下任务:将依赖项文件 (*.deps) 从 SUT 复制到测试项目的 bin 文件夹中.

                The Microsoft.AspNetCore.Mvc.Testing package handles the following tasks: Copies the dependencies file (*.deps) from the SUT into the test project's bin folder.

                但这似乎不起作用.我可以手动复制文件,但这在自动构建场景中不起作用.一种方法是在 TeamCity 中进行构建步骤,但感觉很粗糙.有什么想法吗?

                But that doesn't seem to work. I can copy the file manually, but that doesn't work in a automated build scenario. One way would be to have a build step doing it in TeamCity, but it feels crude. Any ideas?

                如果有帮助的话,我有 GitHub 上的一个副本.

                I have a repro on GitHub if that helps.

                推荐答案

                按照以下步骤为 Asp.Net Core 创建集成测试,目标为 net 47.

                Follow steps below to create Integration Test for Asp.Net Core with targeting net 47.

                1. 创建新建项目->xUnit 测试项目(.Net Core)
                2. 右键新建项目->编辑.csproj->将TargetFramework改为net47
                3. 将项目引用添加到 TestRepro
                4. 安装包Microsoft.AspNetCore.Mvc.Testing
                5. 添加如下测试文件

                1. Create New Project-> xUnit Test Project(.Net Core)
                2. Right click new project->Edit .csproj->Change TargetFramework to net47
                3. Add Project Reference to TestRepro
                4. Install-Package Microsoft.AspNetCore.Mvc.Testing
                5. Add Test file like below

                public class BasicTests
                : IClassFixture<WebApplicationFactory<Startup>>
                {
                    private readonly WebApplicationFactory<Startup> _factory;
                
                    public BasicTests(WebApplicationFactory<Startup> factory)
                    {
                        _factory = factory;
                    }
                
                    [Fact]
                    public async Task TestMethod1()
                    {
                        var client = _factory.CreateClient();
                        var response = await client.GetAsync("/api/values");
                    }
                
                }
                

              • 运行测试项目

              • Run Test Project

                这篇关于使用 .NET Framework 集成测试 ASP.NET Core - 找不到 deps.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!
              • 相关文档推荐

                Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)
                  <tbody id='qrE42'></tbody>
                • <bdo id='qrE42'></bdo><ul id='qrE42'></ul>
                  <legend id='qrE42'><style id='qrE42'><dir id='qrE42'><q id='qrE42'></q></dir></style></legend>

                      <small id='qrE42'></small><noframes id='qrE42'>

                      <i id='qrE42'><tr id='qrE42'><dt id='qrE42'><q id='qrE42'><span id='qrE42'><b id='qrE42'><form id='qrE42'><ins id='qrE42'></ins><ul id='qrE42'></ul><sub id='qrE42'></sub></form><legend id='qrE42'></legend><bdo id='qrE42'><pre id='qrE42'><center id='qrE42'></center></pre></bdo></b><th id='qrE42'></th></span></q></dt></tr></i><div id='qrE42'><tfoot id='qrE42'></tfoot><dl id='qrE42'><fieldset id='qrE42'></fieldset></dl></div>
                        • <tfoot id='qrE42'></tfoot>