3

I am running API e2e tests in VSTS 2017 CD tasks and getting below error at the task (vsTest - End2End Tests)

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

I have below nuget packages in my e2e prject.

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

My project target framework is .Net Core 2.1

As per this I believe everything in place. Not sure what is missing?

VSTS Task

enter image description here

Build.yaml (section)

- 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
Shabar
  • 2,617
  • 11
  • 57
  • 98
  • Apparently `Microsoft.TestPlatform.TestHost` and `Microsoft.NET.Test.Sdk` is supported up to `.NetCoreApp Version=v1.0` Is this the issue? – Shabar Feb 20 '19 at 04:15
  • Running into the same issue, any update on this? All documentation I can find on the subject states that you should do a `dotnet publish` on the project in order to solve the issue, but since I'm trying to run the tests based on the build output of all test projects this doesn't seem practical (I'm guessing you are doing the same thing?) – Wouter Roos Feb 25 '19 at 20:20
  • 1
    I've created an issue for this on github: https://github.com/Microsoft/vstest/issues/1928 – Wouter Roos Feb 25 '19 at 20:36
  • @WouterRoos In the above issue you raised, as the answer specified `dotnet publish`. Can you please elaborate on that? I added what I have in my `build.yaml` – Shabar Mar 31 '19 at 05:25
  • 1
    they recommend publishing all net core test projects using `dotnet publish`, which will include all necessary binaries needed to run the tests using the vstest task. I currently use the `DotNetCoreCLI@2` step with `command` set to `publish`, use a minimatch pattern for the `projects` argument that captures all netcore test projects in the solution and using `--no-build` as `arguments` since my solution has already been built at that point. – Wouter Roos Apr 01 '19 at 07:41
  • @WouterRoos, I updated what added to the build yaml. But it gives below error in that step. `##[error]No web project was found in the repository. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory. ##[error]Project file(s) matching the specified pattern were not found.` Since my project is a `API solution` not a `Web-Project` does that matter? – Shabar Apr 03 '19 at 00:14
  • @WouterRoos, With below build worked, But having the same CD error. `- 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 ` – Shabar Apr 03 '19 at 11:30
  • @WouterRoos Just realised that with above `dotnet publish` I was able to run e2e tests, But after completing tests, still give initial error in the question with. below. `Total tests: Unknown. Passed: 6. Failed: 0. Skipped: 0. Test Run Aborted. Test execution time: 37.6580 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.` – Shabar Apr 04 '19 at 09:22
  • Opened a new question as this is going in different direction. https://stackoverflow.com/questions/55514528/vsts-test-task-failed-despite-of-success-tests – Shabar Apr 04 '19 at 11:19

2 Answers2

2

There are two ways you can handle this.

  1. Publish your project. This makes sure that the test dll and all the dependencies get dropped in a folder. You can give path to this published location and run your test.

  2. You can use the dotnet cli task. If you are using a YAML definition add task as follows:

    - task: DotNetCoreCLI@2
      displayName: 'dotnet test'
      inputs:
        command: test
        projects: '**/*.Tests/*.csproj'
    

Refer: Dotnet CLI task

Richard Garside
  • 87,839
  • 11
  • 80
  • 93
Sarab
  • 21
  • 2
  • I tried the second part which is `yaml` task. it tries to run the test as part of the build, which is not the intention. – Shabar Mar 31 '19 at 05:33
1

Below build.yaml tasks have done the job

- 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)'
Shabar
  • 2,617
  • 11
  • 57
  • 98