【问题标题】:Running dotnet test on webapi app with xunit使用 xunit 在 webapi 应用程序上运行 dotnet 测试
【发布时间】:2018-11-16 17:39:59
【问题描述】:

我正在尝试根据本指南使用最新版本使用 xunit 设置 dotnet core webapi 项目:

https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test (对了,我已经下载了github示例项目,也有同样的错误)

我的项目结构非常基础:

解决方案包含

  • “PrimeService”项目(API)
  • “PrimeService.Test”项目(xunit 测试)

运行“dotnet test”时出现以下错误:

Build started, please wait...
Build started, please wait...
Build completed.

Test run for /media/sf_D_DRIVE/TestDotNetCoreMultiProjectSolution/PrimeService/bin/Debug/netstandard2.0PrimeService.dll(.NETStandard,Version=v2.0)
Microsoft (R) Test Execution Command Line Tool Version 15.7.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
System.IO.FileNotFoundException: Unable to find tests for /media/sf_D_DRIVE/TestDotNetCoreMultiProjectSolution/PrimeService/bin/Debug/netstandard2.0/PrimeService.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further.
   at     Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo)
   at     Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, CancellationToken cancellationToken)
   at     Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)

Test Run Aborted.
Build completed.

Test run for /media/sf_D_DRIVE/TestDotNetCoreMultiProjectSolution/PrimeService.Tests/bin/Debug/netcoreapp2.1/PrimeService.Tests.dll(.NETCoreApp,Version=v2.1)
Microsoft (R) Test Execution Command Line Tool Version 15.7.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

Total tests: 11. Passed: 11. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 1.5172 Seconds

这是 sln 的顶部:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrimeService", "PrimeService\PrimeService.csproj", "{AE9EB41F-3946-4577-AC13-EF9B7117BCD5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrimeService.Tests", "PrimeService.Tests\PrimeService.Tests.csproj", "{4EC37F9F-B5F3-4820-8476-689CE8BC1D2F}"
EndProject

这里是测试csproj

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>

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

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
    <PackageReference Include="xunit" Version="2.3.1" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\PrimeService\PrimeService.csproj" />
  </ItemGroup>

</Project>

这里是 webapi csproj:

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

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

</Project>

有什么线索吗?

谢谢:-)

【问题讨论】:

    标签: visual-studio-code .net-core xunit csproj sln-file


    【解决方案1】:

    原来我在解决方案文件夹中运行“dotnet test”。

    xunit 试图对 api 项目运行测试

    在测试文件夹中运行“dotnet test”时一切正常

    【讨论】:

      猜你喜欢
      • 2020-08-29
      • 2020-11-05
      • 2015-09-07
      • 2015-11-20
      • 2019-05-26
      • 2016-04-11
      • 2021-09-10
      • 2016-04-18
      • 1970-01-01
      相关资源
      最近更新 更多