在.Net Core 2.1中运行集成测试时出现VSTS任务错误

问题描述 投票:2回答:2

我在VSTS 2017 CD任务中运行API e2e测试并在任务中得到以下错误(vsTest - End2End测试)

Unable to find d:\a\r1\a\Project\e2e\bin\Release\netcoreapp2.1\testhost.dll. Please publish your test project and retry.
Unable to find d:\a\r1\a\Project\e2e\obj\Release\netcoreapp2.1\Project.EndToEnd.Integration.Test.deps.json. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". 

我的e2e项目中有以下nuget包。

<PackageReference Include="FluentAssertions" Version="5.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="15.9.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="TestStack.BDDfy" Version="4.3.2" />
<PackageReference Include="TestStack.BDDfy.Xunit" Version="1.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.core" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">

我的项目目标框架是.Net Core 2.1

根据this,我相信一切都到位。不确定缺少什么?

VSTS任务

enter image description here

Build.yaml(部分)

- task: CopyFiles@2
      displayName: "Copy Files to: $(Build.ArtifactStagingDirectory)"
      inputs: 
        contents: "D:/a/1/s/src/xxx.EndToEnd.Integration.Tests/**"
        targetFolder: $(Build.ArtifactStagingDirectory)

- task: DotNetCoreCLI@2
     displayName: "dotnet e2e tests"
     inputs: 
       command: publish
       projects: $(Build.ArtifactStagingDirectory)/src/xxx.EndToEnd.Integration.Tests/xxx.EndToEnd.Integration.Tests.csproj
       arguments : --no-build

    - task: PublishBuildArtifacts@1
      displayName: "Publish End-to-End Tests"
      inputs: 
        artifactName: e2e
        artifactType: container
        pathToPublish: $(Build.ArtifactStagingDirectory)/src/xxx.EndToEnd.Integration.Tests
.net-core azure-devops azure-pipelines-release-pipeline
2个回答
1
投票

有两种方法可以解决这个问题。

  1. 发布您的项目。这可以确保测试dll和所有依赖项都被删除到文件夹中。您可以提供此已发布位置的路径并运行测试。
  2. 您可以使用dotnet cli任务。如果您使用YAML定义添加任务,如下所示:

- task: DotNetCoreCLI@2
        displayName: 'dotnet test'
        inputs:
          command: test
          projects: '<path to sln>'

参考:Dotnet CLI task


1
投票

build.yaml下面完成了任务

- task: DotNetCoreCLI@2
      displayName: "dotnet e2e tests"
      inputs:
        command: publish
        publishWebProjects: false
        projects: '**/**/*.EndToEnd.Integration.Tests.csproj'
        arguments: --output $(Build.ArtifactStagingDirectory)
        zipAfterPublish: false

    - task: PublishBuildArtifacts@1
      displayName: "Publish End-to-End Tests"
      inputs: 
        artifactName: e2e
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
© www.soinside.com 2019 - 2024. All rights reserved.