azure-devops - .NET Core 2.0 xUnit 测试未在 VSTS 中发现

标签 azure-devops xunit

我正在尝试使用 .NET Core 2.0 项目和 xUnit 设置 VSTS 持续集成。

我已经安装了 xunit.runner.visualstudio NuGet 包,在 Visual Studio 中一切正常。

VSTS 找不到要运行的任何测试。

到目前为止我能找到的是 this article ,其中描述了如何通过使用 project.json 使用 .NET Core 1.0 对其进行设置。不幸的是,这行不通,因为 project.json 在 .NET Core 2.0 中消失了。

有什么建议吗?

VSTS 输出:

2017-11-08T20:00:30.4824989Z ##[section]Starting: VsTest - testAssemblies 2017-11-08T20:00:30.4834988Z ============================================================================== 2017-11-08T20:00:30.4834988Z Task : Visual Studio Test 2017-11-08T20:00:30.4834988Z Description : Run tests with Visual Studio test runner 2017-11-08T20:00:30.4834988Z Version : 2.2.3 2017-11-08T20:00:30.4834988Z Author : Microsoft Corporation 2017-11-08T20:00:30.4834988Z Help : More Information 2017-11-08T20:00:30.4834988Z ============================================================================== 2017-11-08T20:00:31.2064989Z Run the tests locally using vstest.console.exe 2017-11-08T20:00:31.2064989Z ======================================================== 2017-11-08T20:00:31.2074983Z Test selector : Test assemblies 2017-11-08T20:00:31.2084986Z Test assemblies : \release*test*.dll,\release\netcoreapp2.0*Unit*.dll,-:\xunit.runner.visualstudio.testadapter.dll,!\obj** 2017-11-08T20:00:31.2084986Z Test filter criteria : null 2017-11-08T20:00:31.2094992Z Search folder : d:\a\1\s 2017-11-08T20:00:31.2094992Z Run settings file : d:\a\1\s 2017-11-08T20:00:31.2094992Z Run in parallel : false 2017-11-08T20:00:31.2115263Z Run in isolation : false 2017-11-08T20:00:31.2184982Z Path to custom adapters : null 2017-11-08T20:00:31.2194992Z Other console options : null 2017-11-08T20:00:31.2194992Z Code coverage enabled : false 2017-11-08T20:00:31.2205509Z VisualStudio version selected for test execution : latest 2017-11-08T20:00:32.3430734Z ======================================================== 2017-11-08T20:00:38.4660600Z [command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" @d:\a_temp\7a0ab851-c4bf-11e7-9264-0bc93cd5677b.txt 2017-11-08T20:00:38.6420650Z Microsoft (R) Test Execution Command Line Tool Version 15.0.26929.2 2017-11-08T20:00:38.6420650Z Copyright (c) Microsoft Corporation. All rights reserved. 2017-11-08T20:00:38.6420650Z 2017-11-08T20:00:38.6420650Z vstest.console.exe 2017-11-08T20:00:38.6430604Z "d:\a\1\s\Salgsapp\MyTestProject.Business.Unit\bin\Release\netcoreapp2.0\MyTestProject.Business.Unit.dll" 2017-11-08T20:00:38.6430604Z "d:\a\1\s\Salgsapp\MyTestProject.Business.Unit\bin\Release\netcoreapp2.0\xunit.runner.reporters.netcoreapp10.dll" 2017-11-08T20:00:38.6430604Z "d:\a\1\s\Salgsapp\MyTestProject.Business.Unit\bin\Release\netcoreapp2.0\xunit.runner.utility.netcoreapp10.dll" 2017-11-08T20:00:38.6430604Z "d:\a\1\s\Salgsapp\MyTestProject.Business.Unit\bin\Release\netcoreapp2.0\xunit.runner.visualstudio.dotnetcore.testadapter.dll" 2017-11-08T20:00:38.6430604Z /logger:"trx" 2017-11-08T20:00:38.6430604Z /TestAdapterPath:"d:\a\1\s" 2017-11-08T20:00:39.2010599Z Starting test execution, please wait... 2017-11-08T20:00:39.7672139Z Warning: No test is available in d:\a\1\s\Salgsapp\MyTestProject.Business.Unit\bin\Release\netcoreapp2.0\MyTestProject.Business.Unit.dll d:\a\1\s\Salgsapp\MyTestProject.Business.Unit\bin\Release\netcoreapp2.0\xunit.runner.reporters.netcoreapp10.dll d:\a\1\s\Salgsapp\MyTestProject.Business.Unit\bin\Release\netcoreapp2.0\xunit.runner.utility.netcoreapp10.dll d:\a\1\s\Salgsapp\MyTestProject.Business.Unit\bin\Release\netcoreapp2.0\xunit.runner.visualstudio.dotnetcore.testadapter.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again. 2017-11-08T20:00:39.7682139Z 2017-11-08T20:00:39.7812142Z 2017-11-08T20:00:40.6140742Z 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 2017-11-08T20:00:40.6140742Z 2017-11-08T20:00:43.0551327Z ##[warning]No results found to publish. 2017-11-08T20:00:43.0711309Z ##[section]Finishing: VsTest - testAssemblies

项目定义:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
    <PackageReference Include="Moq">
      <Version>4.7.142</Version>
    </PackageReference>
    <PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
    <PackageReference Include="MSTest.TestFramework" Version="1.1.18" />
    <PackageReference Include="xunit">
      <Version>2.3.1</Version>
    </PackageReference>
    <PackageReference Include="xunit.runner.visualstudio">
      <Version>2.3.1</Version>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\MyTestProject.Business\MyTestProject.Business.csproj" />
  </ItemGroup>

</Project>

构建配置:

enter image description here

最佳答案

您需要在 IED\Extensions\TestPlatform 文件夹和 Visual Studio 测试任务中的框架选项中指定 vstest.console.exe:

enter image description here

关于azure-devops - .NET Core 2.0 xUnit 测试未在 VSTS 中发现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47188944/

相关文章:

c# - 在 .NET Core 测试项目中构建时禁用/阻止 XUnit 警告

c# - 从 Main 方法/在 MonoDevelop 中运行 XUnit.Net 测试

azure - 如何使用 Azure DevOps API 将工作项与测试结果关联?

Azure Devops - Azure 资源管理器 (ARM) 服务连接

azure - 从 Azure DevOps 发布到 Azure 应用服务 : "You do not have permission to view this directory or page"

azure-devops - Azure Dev Ops 测试步骤未找到测试 (.net 5)

asp.net-core - HubContext的单元测试.net core 2.2 SignalR集线器问题

azure - 针对具有特定源分支的 master 的拉取请求不会触发 Azure 管道

c# - 如何添加使用 Autofixture 创建的 Mock 的特定实现?

xunit - opencover + xunit 没有结果