尽管成功测试,VSTS测试任务仍然失败

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

即使在VsTest任务下通过所有测试后,我也会得到以下错误。

2019-04-04T10:22:14.3913769Z Unable to find d:\a\r1\a\xxx\e2e\bin\Release\netcoreapp2.1\testhost.dll. Please publish your test project and retry.
2019-04-04T10:22:15.1564640Z Results File: d:\a\r1\a\TestResults\VssAdministrator_fv-az153_2019-04-04_10_22_13.trx
2019-04-04T10:22:15.1606430Z 
2019-04-04T10:22:15.1607111Z Test Run Aborted.
2019-04-04T10:22:15.1607372Z Total tests: Unknown. Passed: 6. Failed: 0. Skipped: 0.
2019-04-04T10:22:15.1607627Z Test execution time: 36.3008 Seconds
2019-04-04T10:22:15.3788506Z ##[warning]Vstest failed with error. Check logs for failures. There might be failed tests.
2019-04-04T10:22:15.3917110Z ##[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
2019-04-04T10:22:15.8355860Z ##[error]VsTest task failed

当我在本地尝试下面但没有错误时:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe C:\xxx\src\xxx.EndToEnd.Integration.Tests\bin\Debug\netcoreapp2.1\xxx.EndToEnd.Integration.Tests.dll /logger:trx 2>error.txt

我也尝试过this解决方案,但没有运气。

build.yaml

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

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

    - task: PublishBuildArtifacts@1
      displayName: "Publish End-to-End Tests"
      inputs: 
        artifactName: e2e
        PathtoPublish: '$(Build.ArtifactStagingDirectory)/src/xxx.EndToEnd.Integration.Tests'

enter image description here

我注意到下面的日志中有不同的路径(即发布管道 - d:\a\r1\a\EstimationCore\e2e\xxx.EndToEnd.Integration.Tests和Build管道-d:\a\1\a\src\xxx.EndToEnd.Integration.Tests\bin\Release\netcoreapp2.1

完整日志:

Release pipeline - Download artifact - EstimationCore - e2e
2019-04-07T09:05:10.8843174Z Downloaded e2e/xxx.EndToEnd.Integration.Tests/xxx.EndToEnd.Integration.Tests.deps.json to d:\a\r1\a\EstimationCore\e2e\xxx.EndToEnd.Integration.Tests\xxx.EndToEnd.Integration.Tests.deps.json

Build pipeline - Copy Files to: $(Build.ArtifactStagingDirectory)
Copying d:\a\1\s\src\xxx.EndToEnd.Integration.Tests\bin\Release\netcoreapp2.1\xxx.EndToEnd.Integration.Tests.deps.json to d:\a\1\a\src\xxx.EndToEnd.Integration.Tests\bin\Release\netcoreapp2.1\xxx.EndToEnd.Integration.Tests.deps.json
asp.net-core azure-devops azure-pipelines vstest
2个回答
2
投票

返回的任务为:Test Run Aborted.因此并非所有测试都已执行。这是可能的原因:

Unable to find d:\a\r1\a\xxx\e2e\bin\Release\netcoreapp2.1\testhost.dll. Please publish your test project and retry.

我很高兴这导致测试执行失败:)。

该错误提到您应该在运行测试之前发布测试项目,以确保将所有依赖项复制到输出目录中。

你没有分享你工作流程的其余部分,但是我会冒险跟随错误中提到的事情很有意义。

确保所有路径都正确,以便找到正确的文件。在构建中,您可以控制通过--output发布的路径,并根据人工制品名称将每个人工制品下载到特定位置。这是为了确保具有多个人工制品的版本不会意外地覆盖彼此的文件。


0
投票

在以下更改为build.yaml之后,测试成功运行。因此,您可以看到问题与文件夹路径有关

task: CopyFiles@2没有必要

- 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.