web-dev-qa-db-ja.com

Azure DevOpsで実行すると、xUnitテストが失敗する

さまざまなAzureDevOps CI/DI機能を試すための非常に単純なテストプロジェクトを作成しています。このプロジェクトには、ASP.NET CoreWebサイトプロジェクトとxUnitユニットテストプロジェクトを使用したソリューションが含まれています。単体テストはローカルマシンで正しく実行されます(VisualStudioランナーとdotnet testでテストされていますが、Azureビルドで動作させることはできません。

Azureでの単体テストステップの出力は次のとおりです。

##[section]Starting: Test Assemblies
==============================================================================
Task         : Visual Studio Test
Description  : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
Version      : 2.147.0
Author       : Microsoft Corporation
Help         : [More information](https://go.Microsoft.com/fwlink/?LinkId=835764)
==============================================================================
SystemVssConnection exists true
SystemVssConnection exists true
SystemVssConnection exists true
Running tests using vstest.console.exe runner.
======================================================
Test selector : Test assemblies
Test filter criteria : null
Search folder : D:\a\1\s
VisualStudio version selected for test execution : latest
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : true
SystemVssConnection exists true
Run the tests locally using vstest.console.exe
========================================================
Test selector : Test assemblies
Test assemblies : **\release\netcoreapp2.2\*test*.dll,!**\obj\**
Test filter criteria : null
Search folder : D:\a\1\s
Run settings file : D:\a\1\s
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : false
Rerun failed tests: false
VisualStudio version selected for test execution : latest
========================================================
======================================================
[command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" @D:\a\_temp\e481a311-390d-11e9-aa01-4f08eeab4c37.txt
Microsoft (R) Test Execution Command Line Tool Version 15.9.0
Copyright (c) Microsoft Corporation.  All rights reserved.

vstest.console.exe 
"D:\a\1\s\tests\ContosoUniversity.Tests\bin\Release\netcoreapp2.2\ContosoUniversity.Tests.dll"
"D:\a\1\s\tests\ContosoUniversity.Tests\bin\Release\netcoreapp2.2\xunit.runner.visualstudio.dotnetcore.testadapter.dll"
/logger:"trx"
/TestAdapterPath:"D:\a\1\s"
Starting test execution, please wait...
Test run will use DLL(s) built for framework .NETCoreApp,Version=v2.2 and platform X86. Following DLL(s) do not match framework/platform settings.
xunit.runner.visualstudio.dotnetcore.testadapter.dll is built for Framework 1.0 and Platform AnyCPU.
Go to http://go.Microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.

[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.1 (64-bit .NET Core 4.6.27207.03)
[xUnit.net 00:00:04.36]   Discovering: ContosoUniversity.Tests
[xUnit.net 00:00:04.43]   Discovered:  ContosoUniversity.Tests
[xUnit.net 00:00:04.44]   Starting:    ContosoUniversity.Tests
[xUnit.net 00:00:04.93]   Finished:    ContosoUniversity.Tests
Passed   ContosoUniversity.Controllers.HomeControllerTest.Index_Renvoie_Le_Bon_Modele
Unable to find D:\a\1\s\tests\ContosoUniversity.Tests\bin\Release\netcoreapp2.2\xunit.runner.visualstudio.dotnetcore.testadapter.deps.json. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".
Results File: D:\a\1\s\TestResults\VssAdministrator_fv-az561_2019-02-25_14_59_22.trx

Total tests: Unknown. Passed: 1. Failed: 0. Skipped: 0.
Test Run Aborted.
Test execution time: 8.5546 Seconds
##[warning]Vstest failed with error. Check logs for failures. There might be failed tests.
##[error]Error: The process 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe' failed with exit code 1
##[error]VsTest task failed.
##[section]Async Command Start: Publish test results
Publishing test results to test run '1000118'
Test results remaining: 1. Test run id: 1000118
Published Test Run : https://orkeis-proj1.visualstudio.com/MyFirstProject_Test/_TestManagement/Runs#runId=1000118&_a=runCharts
##[section]Async Command End: Publish test results
##[section]Finishing: Test Assemblies

不足しているjsonファイルがどのようにあるのか理解できていません。エラーはMicrosoft.NET.Test.Sdkをインストールすることを示唆していますが、プロジェクトファイルで参照されています:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>

    <IsPackable>false</IsPackable>

    <RootNamespace>ContosoUniversity</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\src\ContosoUniversity.csproj" />
  </ItemGroup>

</Project>

だから私が欠けているものについてのヒントをいただければ幸いです。

6
Shtong

@Shtongのおかげで、xunitパイプラインビルドを修正することができました。これは将来の参考のために私のYAMLファイルです:

- task: VSTest@2
  inputs:    
    testAssemblyVer2: |
      **\bin\$(BuildConfiguration)\**\*tests*.dll         
      !**\obj\**
      !**\xunit.runner.visualstudio.testadapter.dll
      !**\xunit.runner.visualstudio.dotnetcore.testadapter.dll
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    otherConsoleOptions: '/platform:x64 /Framework:.NETCoreApp,Version=v3.1 /logger:console;verbosity="normal" '
1
D.Rosado