Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.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
Asp.net core 在ASP.Net Core 1.0项目上使用xUnit并在Visual Studio Team Services托管代理上生成时,未发现任何测试_Asp.net Core_Automated Tests_Azure Devops_Xunit_Azure Pipelines - Fatal编程技术网

Asp.net core 在ASP.Net Core 1.0项目上使用xUnit并在Visual Studio Team Services托管代理上生成时,未发现任何测试

Asp.net core 在ASP.Net Core 1.0项目上使用xUnit并在Visual Studio Team Services托管代理上生成时,未发现任何测试,asp.net-core,automated-tests,azure-devops,xunit,azure-pipelines,Asp.net Core,Automated Tests,Azure Devops,Xunit,Azure Pipelines,在Visual Studio Team Services上构建时,我的ASP.Net Core 1.0应用程序中的xUnit测试没有被发现,这是一个问题 测试项目正在成功构建中,但没有给出测试结果。我在日志中找到有关Visual Studio测试步骤的以下消息: ****************************************************************************** Starting task: Test Assemblies **\*test

在Visual Studio Team Services上构建时,我的ASP.Net Core 1.0应用程序中的xUnit测试没有被发现,这是一个问题

测试项目正在成功构建中,但没有给出测试结果。我在日志中找到有关Visual Studio测试步骤的以下消息:

******************************************************************************
Starting task: Test Assemblies **\*test*.dll;-:**\xunit.runner.visualstudio.testadapter.dll
******************************************************************************
Executing the powershell script: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\default\tasks\VSTest\1.0.29\VSTest.ps1
Working folder: C:\a\1
Executing C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "C:\a\1\s\artifacts\bin\project.test\Debug\dnx451\project.test.dll"  /EnableCodeCoverage /InIsolation /logger:trx
Microsoft (R) Test Execution Command Line Tool Version 14.0.24720.0
Copyright (c) Microsoft Corporation.  All rights reserved.
Starting test execution, please wait...
Warning: No test is available in C:\a\1\s\artifacts\bin\project.test\Debug\dnx451\project.test.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
Attachments:
  C:\a\1\TestResults\0ad44b11-4dd4-41ba-a0bf-66d9cd487a3c\buildguest_TASKAGENT5-0007 2016-03-01 07_33_04.coverage
Information: Additionally, you can try specifying '/UseVsixExtensions' command if the test discoverer & executor is installed on the machine as vsix extensions and your installation supports vsix extensions. Example: vstest.console.exe myTests.dll /UseVsixExtensions:true
No results found to publish.
测试是这样编写的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Xunit;

namespace project.tests
{
    public class ProjectTests
    {
        [Fact]
        public void PassingTest()
        {
            Assert.Equal(4, Add(2, 2));
        }

        [Fact]
        public void FailingTest()
        {
            Assert.Equal(5, Add(2, 2));
        }

        int Add(int x, int y)
        {
            return x + y;
        }
    }
}
测试在本地运行正常,但在VisualStudioTeamServices上运行不正常

作为参考,这是my project.json

{
  "authors": [ "Tom Reiertsen" ],
  "commands": {
    "test": "xunit.runner.dnx"
  },
  "dependencies": {
    "project": "1.0.0-rc1-update1",
    "Microsoft.AspNet.Hosting": "1.0.0-rc1-final",
    "Microsoft.AspNet.TestHost": "1.0.0-rc1-final",
    "Microsoft.AspNet.WebApi.Client": "5.2.3",
    "Microsoft.CSharp": "4.0.1-beta-23516",
    "System.Collections": "4.0.11-beta-23516",
    "System.Linq": "4.0.1-beta-23516",
    "System.Runtime": "4.0.21-beta-23516",
    "System.Threading": "4.0.11-beta-23516",
    "xunit": "2.1.0",
    "xunit.runner.dnx": "2.1.0-rc1-build204",
    "xunit.runner.visualstudio": "2.1.0"
  },
  "description": "project.test Class Library",
  "frameworks": {
    "dnx451": { }
  },
  "licenseUrl": "",
  "projectUrl": "",
  "tags": [ "" ],
  "version": "1.0.0-rc1-update1"
}
在“高级执行选项\自定义测试适配器路径”中输入“$(Build.SourcesDirectory)\SolutionFolderName\packages”,将测试适配器设置为xUnit。有关详细信息,请参阅此链接:

更新: 我只是创建了一个示例应用程序来测试这一点,并得到与您相同的问题。但是,如果我将xunit程序集文件与test.dll一起复制到“dnx451”文件夹中,测试将成功完成。

由于您正在处理Asp.Net核心项目,并且已导入DNX runner,因此还可以添加“命令行”任务以使用DNX test命令直接运行测试。
由于找不到vstest的xunit测试适配器,因此未发现测试。这是你能做的

  • 将引用添加到测试项目中
  • 添加restore nuget包作为构建定义的第一步

  • vstest不应该能够检测到您的xunit测试适配器,然后发现并执行xunit测试

    有人发布了此消息,我尝试了此方法,效果良好

  • 在执行选项->测试程序集中,放置 **\test**\project.json
  • 预先执行选项->其他控制台选项,put/usevsixtensions:true/logger:trx
  • 以及visual studio团队服务的最终结果

    我尝试了“$(Build.SourcesDirectory)\test\packages”和“$(Build.SourcesDirectory)\test\project.test\packages”但没有成功,Visual Studio测试步骤将显示错误。然后我注意到包被还原到的位置,并输入“C:\Users\buildguest\.dnx\packages\xunit.runner.visualstudio\2.1.0”,然后Visual Studio测试步骤成功,但出现了与我的初始问题相同的警告(未找到测试)所以它仍然不起作用。@TomRay74我只是创建了一个ASP.Net核心项目进行测试,并且可以得到与您相同的问题。有关详细信息,请参阅我的更新答案。我仍然无法使其正常工作。我试图将xUnit dll复制到与test.dll相同的文件夹中,但问题仍然存在。@TomRay74与我的屏幕截图中的文件相同?您是否从“高级”中删除了“$(Build.SourcesDirectory)\SolutionFolderName\packages”复制xUnit DLL后?我已经在项目中安装了xUnit NuGet软件包,您可以从上面我的project.json依赖项中看到。问题是$(Build.SourcesDirectory)\packages\将无法工作,因为project.json NuGet机制将软件包还原到您的用户临时目录,不是\packages@TomRay74您是否尝试更新您的代理。您当前的任务版本-29非常旧。如果这不是一个选项,请在高级选项->自定义测试适配器路径中显式提供xunit适配器路径。此答案与xunit无关,不适用于xunit。xunit是Visual studio 2015的官方测试运行程序。我自己测试了这个,并与xUnit合作。我附上了截图来证明这是有效的