在Visual Studio Team Services托管代理上构建的ASP.Net Core 1.0项目上没有使用xUnit发现任何测试

时间:2016-03-01 07:45:40

标签: asp.net-core automated-tests azure-devops xunit azure-pipelines

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

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

******************************************************************************
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;
        }
    }
}

测试在本地运行得很好,但在Visual Studio Team Services上没有。

作为参考,这是我的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"
}

3 个答案:

答案 0 :(得分:1)

输入" $(Build.SourcesDirectory)\ SolutionFolderName \ packages" in"高级执行选项\自定义测试适配器的路径"将测试适配器设置为xUnit。有关详细信息,请参阅此链接:xUnit or NUnit with Visual Studio Online Build

<强>更新: 我只是创建一个示例应用程序来测试这个并得到同样的问题。但是,如果我将xunit程序集文件复制到&#34; dnx451&#34;文件夹与test.dll一起,测试将成功完成。 enter image description here enter image description here

由于您正在开发Asp.Net Core项目并已导入DNX runner,您还可以添加一个&#34;命令行&#34;任务使用dnx test命令直接运行测试。 enter image description here

答案 1 :(得分:0)

由于未找到针对vstest的xunit测试适配器,因此未发现测试。这是你可以做的

  1. xunit test adapter nuget引用添加到您的测试项目
  2. 添加还原nuget包作为构建定义的第一步
  3. vstest应该无法检测到您的xunit测试适配器,然后发现并执行xunit测试

答案 2 :(得分:0)

有人发布了这个,我试试这个并且它有效 http://blogs.perficient.com/microsoft/2016/08/unit-test-with-net-core-and-vsts/

  1. 在执行选项中 - &gt;测试组件,放 ** \试验** \ project.json
  2. 预先执行选项 - &gt;其他控制台选项,put / UseVsixExtensions:true / logger:trx
  3. enter image description here

    enter image description here

    以及Visual Studio团队服务的最终结果 enter image description here