Nayden Van
Nayden Van

Reputation: 1539

azure pipeline No test result files were found

I have an azure pipeline to build and publish a c# project to a docker image. everything works just fine but today I wanted to add a unit test this pipeline.

so I added the task for it.

as follow:

  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '5.x'

- task: DotNetCoreCLI@2
    displayName: 'DotNet - Restore'
    inputs:
      command: 'restore'
      projects: $(project)
      noCache: true
      versioningScheme: 'off'
      vstsFeed: 'feed'

  - task: DotNetCoreCLI@2
    displayName: "Run unit tests - $(Build.BuildNumber)"
    inputs:
      command: 'test'
      arguments: '--no-build --configuration $(Build.BuildNumber)'
      projects: 'path/to/Tests.csproj'
      publishtestResults: true

  - task: DotNetCoreCLI@2
    name: 'DotnetPublish'
    displayName: 'dotnet - Publish'
    inputs:
      command: 'publish'
      projects: $(project)
      arguments: '-o publish/projectapi -c release'
      modifyOutputPath: false
      zipAfterPublish: false
      publishWebProjects: false

  - task: Docker@2
    name: 'dockerBuildAndPush'
    displayName: 'docker - Build & Push'
    inputs:
      repository: $(imageRepository)
      Dockerfile: $(dockerfilePath)
      containerRegistry: ${{ variables.dockerRegistryServiceConnection }}
      buildContext: ${{ variables.buildContext }}
      tags: |
        $(Build.BuildNumber)
        latest

when I run the pipeline, on the test task, it take less than 2 second and it returns

##[warning]No test result files were found.

and if I head to the tests tab, I see the message that there are no tests to display.

Am I doing something wrong in my pipeline configuration?

thank you so much for any help

EDIT: There are some update about this. The issue was related to the fact that I didn't have a build task for the test csproj. When I implemented the task and run the pipeline. I got an error about a nuget package not found (private nuget). In my vsfeed in the devops panel, I can see that package exists, but for some reason the pipeline fails because it doesn't see that package. Did this ever happened to anyone and knows a workaround?

Upvotes: 5

Views: 6830

Answers (2)

scottpetrovic
scottpetrovic

Reputation: 73

For me, the problem was also was related to the .Net Restore task. The 'projects' property was originally set to the web.csproj file, so the Tests project was not restoring. I switched out the 'projects' value to my entire solution file and the warning went away.

- task: DotNetCoreCLI@2
    displayName: 'DotNet - Restore'
    inputs:
      command: 'restore'
      projects: './EntireProject.sln'
      noCache: true
      versioningScheme: 'off'
      vstsFeed: 'feed'

Upvotes: 0

Naylor
Naylor

Reputation: 903

Try removing the --no-build from the arguments. Nothing in the pipeline before it appears to run the build. You also may need to make sure that your dotnet restore command is restoring the packages for the test project. (I can't tell from if the restore for $(project) would or not)

Upvotes: 4

Related Questions