TheEdge
TheEdge

Reputation: 9861

Cannot get Azure DevOps to recognise and run my NUnit tests

I am trying to get my NUnit tests to run in an Azure DevOps pipeline. However even though I can see my project being built:

Done Building Project "D:\a\3\s\Src\Standard\Splyce.Standard.Common.Tests\Splyce.Standard.Common.Tests.csproj" (default targets).

I still get the following:

##[warning]No test assemblies found matching the pattern: **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**.

I followed the instructions from https://developercommunity.visualstudio.com/solutions/357521/view.html to add a "vsTest - Test Assemblies" step, and did not change any settings.

My test project does include the NUnit3 Test Adapter:

Test Adapter

So I am pretty sure this is only a pathing problem. However the globbing on the assembly selector should work to find it. This is my on disk folder structure for the solution in question:

UPDATE: Show physical on disk layout includes Src.

E:.
+---BuildProcessTemplates
\---Src
    +---AgentApiServer
    |   +---Splyce.AgentApi.Common
    |   |   +---bin
    |   |   |   \---Debug
    |   |   |       \---netcoreapp2.1
    |   |   +---MirrorEngine
    |   |   |   \---Framework
    |   |   |       +---Dtos
    |   |   |       +---Enums
    |   |   |       +---Events
    |   |   |       \---Interfaces
    |   |   \---obj
    |   |       \---Debug
    |   |           \---netcoreapp2.1
    |   \---Splyce.AgentApi.Server
    |       +---bin
    |       |   \---Debug
    |       |       +---netcoreapp2.0
    |       |       +---netcoreapp2.1
    |       |       \---netcoreapp2.2
    |       +---obj
    |       |   \---Debug
    |       |       +---netcoreapp2.0
    |       |       +---netcoreapp2.1
    |       |       \---netcoreapp2.2
    |       +---Properties
    |       \---wwwroot
    \---Standard
        +---Common
        +---packages
        |   +---NUnit.3.11.0
        |   |   +---build
        |   |   \---lib
        |   |       +---net20
        |   |       +---net35
        |   |       +---net40
        |   |       +---net45
        |   |       +---netstandard1.4
        |   |       \---netstandard2.0
        |   +---NUnit3TestAdapter.3.13.0
        |   |   \---build
        |   |       +---net35
        |   |       \---netcoreapp1.0
        |   \---Shouldly.3.0.2
        |       \---lib
        |           +---net40
        |           +---net451
        |           +---netstandard1.3
        |           \---netstandard2.0
        +---Splyce.Standard.Common
        |   +---bin
        |   |   \---Debug
        |   |       \---netstandard2.0
        |   +---Helpers
        |   \---obj
        |       \---Debug
        |           \---netstandard2.0
        +---Splyce.Standard.Common.Tests
        |   +---bin
        |   |   +---Debug
        |   |   \---Release
        |   +---obj
        |   |   \---Debug
        |   |       \---TempPE
        |   \---Properties
        +---Splyce.Standard.DbMigrations
        |   +---bin
        |   |   \---Debug
        |   |       \---netstandard2.0
        |   +---Dtos
        |   +---Framework
        |   |   +---DbUp
        |   |   +---Dtos
        |   |   |   \---DatabaseMigrationsManager
        |   |   +---Enums
        |   |   \---Events
        |   \---obj
        |       \---Debug
        |           \---netstandard2.0
        +---Splyce.Standard.Messaging
        |   +---bin
        |   |   \---Debug
        |   |       \---netstandard2.0
        |   +---Client
        |   |   +---Publisher
        |   |   \---Subscriber
        |   +---Framework
        |   |   +---Interfaces
        |   |   \---Messages
        |   +---Messages
        |   |   +---Health
        |   |   \---Mirroring
        |   \---obj
        |       \---Debug
        |           \---netstandard2.0
        \---UnitTestProject1
            +---bin
            |   \---Debug
            |       \---netcoreapp2.2
            \---obj
                \---Debug
                    \---netcoreapp2.2

Can anyone give me any ideas here on how to get Azure to find my test assemblies.

Upvotes: 1

Views: 2287

Answers (2)

kelseap
kelseap

Reputation: 21

I was experiencing a similar issue, but the root cause ended up being related to the msbuildArgs parameter on my VSBuild task being set to '/target:Publish'. The VSBuild log was letting me know the project was unpublishable, and that was also preventing it from building.

Done Building Project "D:\BuildAgents\Agent03_work\1\s\Calculators\Calculators.csproj" (Publish target(s)). Project "D:\BuildAgents\Agent03_work\1\s\Workbench.sln" (1) is building "D:\BuildAgents\Agent03_work\1\s\Calculators.Tests\Calculators.Tests.csproj" (5) on node 1 (Publish target(s)). _DeploymentUnpublishable: Skipping unpublishable project. Done Building Project "D:\BuildAgents\Agent03_work\1\s\Calculators.Tests\Calculators.Tests.csproj" (Publish target(s)).

My resolution was just to add an additional build task. Here's my updated yaml:

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    vsVersion: '16.0'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: '**\*Test*.dll'
    searchFolder: '$(System.DefaultWorkingDirectory)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    vsVersion: '16.0'
    platform: '$(buildPlatform)'
    msbuildArgs: '/target:Publish'
    configuration: '$(buildConfiguration)'

Followed by CopyFiles and PublishBuildArtifacts tasks.

Upvotes: 2

jessehouwing
jessehouwing

Reputation: 114641

What's the root folder for your search? By default that's also the root folder used to look up Test Adapters. The default is the Repository Root, but since you're building a specific csproj I suspect you may have scoped this to the project root instead of the solution root.

enter image description here

You can override to a more specific path for the test adapters:

enter image description here

You should probably stick something like: $(Build.SourcesDirectory)\packages\ in there.

If your project is .NET Core, you can also try running a dotnet test task instead of vstest.

Upvotes: 0

Related Questions