Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么测试方法在azure devops构建管道、dotnet测试任务中未完成_C#_Testing_.net Core_Moq_Xunit - Fatal编程技术网

C# 为什么测试方法在azure devops构建管道、dotnet测试任务中未完成

C# 为什么测试方法在azure devops构建管道、dotnet测试任务中未完成,c#,testing,.net-core,moq,xunit,C#,Testing,.net Core,Moq,Xunit,我正在azure devops构建管道中运行dotnet测试任务 测试在我的机器上的VisualStudio(16.4.3)IDE中很好地完成,还使用CLI和“dotnet test”命令 然而,在azure中它失败了。我的解决方案是一个.NETCore3.1API。该测试在控制器测试中返回CreatedAtRouteResult类型。我正在断言IsType。尽管在Azure中,它返回一个ObjectResult,而不是预期的CreatedAtRouteResult。附加信息,测试项目正在使用x

我正在azure devops构建管道中运行dotnet测试任务

测试在我的机器上的VisualStudio(16.4.3)IDE中很好地完成,还使用CLI和“dotnet test”命令

然而,在azure中它失败了。我的解决方案是一个.NETCore3.1API。该测试在控制器测试中返回
CreatedAtRouteResult
类型。我正在断言
IsType
。尽管在Azure中,它返回一个
ObjectResult
,而不是预期的
CreatedAtRouteResult
。附加信息,测试项目正在使用xUnit和Moq。虽然这些框架与错误无关

我无法导航到我们私有云中使用的代理上的build文件夹

Visual Studio中的测试结果以及在CLI中使用dotnet测试的结果

开发人员CLI,使用“dotnet测试”

测试运行 …\SqlViewService.Tests\bin\Debug\netcoreapp3.1\SqlViewService.Tests.dll(.NETCoreApp,版本=v3.1) Microsoft(R)测试执行命令行工具版本16.3.0 版权所有(c)微软公司。版权所有

正在启动测试执行,请稍候

总共有1个测试文件与指定的模式匹配

测试运行成功。测试总数:10 通过时间:10总时间:150151秒

…\SqlViewService.Tests>

azure生成任务中的错误代码:

我按照这个链接来设置管道,尽管我没有使用YAML,而是使用GUI构建管道任务。像这样:

发布如下所示:

在azure任务和本地环境中,测试执行命令行工具版本均为16.3.0

非常基本的设置,但是无法找出不匹配出现的位置。你有什么想法或解决办法吗

我一直在研究这篇文章:

根据注释中的要求,试验方法:

 public IActionResult UpdateView([FromBody] SqlViewModel sqlView, [FromHeader, Required] int correlationId, DateTime date)
        {
            try
            {
                ThreadContext.Properties["RunID"] = correlationId;
                ThreadContext.Properties["Username"] = Environment.UserName;

                _logger.LogInformation("SQL View Model: " + sqlView.Name + ", " + sqlView.Database + ", " +
                                       sqlView.UsePrecedingWorkdayLogic);
                foreach (var sourceInfo in sqlView.Sources)
                {
                    _logger.LogInformation("Table Info: " + sourceInfo.Name + ", " + sourceInfo.SearchString + ", " +
                                           sourceInfo.DateFormat);
                }

                ViewLogic.SetViewDate(sqlView, date);
                //Returns the location in the response header
                return CreatedAtRoute("GetView", new { view = sqlView.Name }, sqlView);
            }
            catch (Exception ex)
            {
                return StatusCode(StatusCodes.Status500InternalServerError, "Database failure: " + ex.Message);
            }
        }

应该有一个名为“测试”的选项卡。默认情况下,它应该过滤失败的测试。它是否有任何其他信息(如堆栈跟踪)可能有助于故障排除?显示
UpdateView()
method@haim770方法包括。如果您在这里看到任何东西,请告诉我,或者如果您有任何想法,请告诉我,为什么在VisualStudio和本地使用dotnet test会成功。但不在我的azure构建管道中。
ObjectResult
在调用
StatusCode()
方法时返回。在你的代码中,当你捕获一个异常时,它就会被使用。当代码在Azure管道中运行时,似乎确实出现了一些数据库(或模拟数据库)故障。首先,我将更改测试代码,以打印与返回的
ObjectResult
Remove
try。。catch
,如果引发异常,将返回500个响应。但是在你当前的问题上提供更好的指导。