21

I am trying to implement a Gated Check-In process in Azure DevOps (VSTS) based on the success of the unit tests. However, I am consistently getting this warning/error that assemblies are not found.

##[warning]No test assemblies found matching the pattern: **\*Test*.dll,!**\*TestAdapter.dll,!**\obj\**.
##[debug]Processed: ##vso[task.issue type=warning;]No test assemblies found matching the pattern: **\*Test*.dll,!**\*TestAdapter.dll,!**\obj\**.
======================================================

All my unit tests run successfully in Visual Studio 2017 in Test Explorer locally.

The Azure DevOps documentation seems straightforward but it does not work when I follow it.

I am using a Hosted VS2017 Agent. The CI Build itself succeeds upon check in to TFS source control.

Log

screen 1
screen 2 screen 3 screen 4 screen 5 [screen 6]

Andy Miller
  • 211
  • 1
  • 2
  • 4

5 Answers5

24

The "old" .NET had the files located in the Release folder (which is described by the BuildConfiguration variable).

.NET Core builds contain an extra folder:

Folder structure

YourNamespaceHere.UnitTests > bin > Release > netcoreapp2.1 > dll's

When you add an extra wildcard, the build will find the unittest dll's.

**\$(BuildConfiguration)\*\*unittests.dll

I have renamed the *Tests* part to *unittests.dll as my project also contains integrationtests.

enter image description here

JeroenW
  • 753
  • 6
  • 16
9

I had this same problem in a .Net Core 2.1 project. In the "other console options" you want to add:

/Framework:.NETCoreApp,Version=v2.1 /logger:console;verbosity="normal"

Please be aware that I had another problem not related to this, but on the same task. I was getting an error about not finding a test file result output for the TestPlatform dlls. So, I added this filter to the existing test files:

!**\*Microsoft.VisualStudio.TestPlatform*

My final yaml looks like this:

- task: VSTest@2
  displayName: 'Run Unit Tests'
  inputs:
    testAssemblyVer2: |
     **\$(BuildConfiguration)\*test*.dll
     **\$(BuildConfiguration)\**\*test*.dll
     !**\*Microsoft.VisualStudio.TestPlatform*
     !**\obj\**
    vstestLocationMethod: 'location'
    vstestLocation: 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\'
    codeCoverageEnabled: True
    otherConsoleOptions: '/platform:x64 /Framework:.NETCoreApp,Version=v2.1 /logger:console;verbosity="normal" '
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
Antebios
  • 1,681
  • 1
  • 13
  • 22
  • Thank You So Much! I've been wrecking my brain on this for a week. Yes, I am on .NET Core and Visual Studio 2017. Let me try this and see. – Andy Miller Sep 20 '18 at 23:02
  • Please let me know if it works or not. If it does, please upvote the answer so others can see that it was the solution to your question. – Antebios Sep 21 '18 at 14:39
  • I got further with it, per your advice. Here is a log with the new error I am getting. ##vso[task.complete result=Failed;]VsTest task failed. I have a text file with a full log but not sure how to attached it. I don't seem to be allowed to insert a link in the original comment, not a CDN link to my log file. – Andy Miller Sep 21 '18 at 23:55
  • Please take a look at the full log, I edited my post and included a Log link above. – Andy Miller Sep 22 '18 at 01:18
  • At least your tests are executing this time, but the errors I see are: Incorrect format for TestCaseFilter Error: Invalid Condition '!**\*Microsoft.VisualStudio.TestPlatform*'. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed. No test matches the given testcase filter `!**\*Microsoft.VisualStudio.TestPlatform*` in D:\a\3\s\Avontus.QuantifySite.IntegrationTests\bin\Debug\netcoreapp2.0\Avontus.QuantifySite.IntegrationTests.dll Test Run Failed. – Antebios Sep 25 '18 at 16:57
  • 1
    Maybe leave that 1 filter for 'Microsoft.VisualStudio.TestPlatform' off and try again. Maybe remove CodeCoverage argument. Play with the arguments and get back to this thread or try googling more. I'm sorry, but I haven't tried to build a Xamarin project. Also, make sure that are you passing the correct .Net Core version that you are using to compile. I can feel it that you are aaalllmooost there. – Antebios Sep 25 '18 at 17:07
2

I had the same issue and spent ages trying out different file matching patterns, .NET Core versions, etc.

My build pipeline was publishing the tests to the artifacts directory, which you can conveniently do with a publish command. But my testing agent was not downloading the artifacts and that was the problem. I was using different agents for deployment and for testing so I didn't notice that something was wrong because the deployment agent had access to the resources but the test agent didn't.

Make sure you've selected to download the artifacts in the Artifact Download section of the agent configuration tab. It's all the way down and I think by default it showed my build package, making me think that it is being downloaded. But I still had to expand it and tick the 'select all artifacts' option. If it's configured fine, you should have a 'Download artifact' task in your deployment logs.

My build pipeline's publish task:

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '**/*ServiceTests.csproj'
    arguments: '-c $(buildConfiguration) -o $(Build.ArtifactStagingDirectory)/servicetests'
    modifyOutputPath: false
    zipAfterPublish: false

My test agent Artifact Download section: enter image description here

My test task's selection config: enter image description here

1

I had the same issue when my Unit Test task wanted to run (I'm using .Net Core). It seems like a path naming issue. My Unit Test project is called

SimpleExample.UnitTests

but the path of "DotNetCoreCLI@2" task in the YAML file was set to

'**/*Tests/*.csproj'

So I just change the project path of the unit test task to be like the second part (after dot) of my Unit Tests project in Visual Studio.

The path of my unit test project in Visual Studio 2017: Desktop\Azure-DevOps-Test\SimpleExample.UnitTests

The YAML task that runs the unit tests [For .Net projects]:

- task: DotNetCoreCLI@2
    displayName: 'Runing Unit Tests'
    inputs:
      command: test
      projects: '**/*UnitTests/*.csproj'
      arguments: '--configuration $(buildConfiguration)'
Alireza Sattari
  • 181
  • 2
  • 12
0

Probably very old but i recenly had this same issue and i was able to solve it by using the following

          - task: VSTest@2
            displayName: 'VsTest - testAssemblies'
            inputs:
              testAssemblyVer2: |
                **\$(buildConfiguration)\*[Tt]est.dll
                **\$(buildConfiguration)\*test*.dll
                !**\*Microsoft.VisualStudio.TestPlatform*
                !**\obj\**
              runOnlyImpactedTests: true
              codeCoverageEnabled: true
              testRunTitle: 'Unit test Results for $(Build.BuildNumber)'
              platform: '$(buildPlatform)'
              configuration: '$(buildConfiguration)'
              failOnMinTestsNotRun: true
              rerunFailedTests: false

one thing you need to make sure of is to make sure to add the Copy file task after the build:

          - task: CopyFiles@2
            displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
            inputs:
              SourceFolder: '$(system.defaultworkingdirectory)'
              Contents: '**\bin\$(buildConfiguration)\**'
              TargetFolder: '$(build.artifactstagingdirectory)'
            condition: succeededOrFailed()

then the VStest task comes immediately after the copy task

Murphie
  • 29
  • 3