1
votes

I have a C# solution where there are several unit test projects that use xUnit and an "end to end" tests project that uses NUnit. (This is intentional and fine so I'd appreciate not trying to convince me to ditch one for the other, thanks)

I use an Azure DevOps Pipeline to build, test and package my solution. This is my test step (from azure-pipelines.yml) at the moment:

- task: DotNetCoreCLI@2
  displayName: 'Run tests in solution'
  inputs:
    command: 'test'
    arguments: '--configuration $(buildConfiguration) --collect "Code coverage" --filter Category!=Integration'
    publishTestResults: true

When I run this my pipeline fails with this error message:

An exception occurred while invoking executor 'executor://nunit3testexecutor/': Unexpected Word 'Category' at position 29 in selection expression.

I'm pretty sure this happens because NUnit is getting picked up and it does not understand the Category filter term. (NUnit expects the term TestCategory instead)

I tried getting the pipeline to not pick up the NUnit project (called "EndToEnd")this way:

--filter FullyQualifiedName!~EndToEnd&Category!=Integration'

But this does not work and I get the same error message.

How can I get Azure DevOps Pipelines to only run the tests in my xUnit projects in this step and not fail because of the presence of the NUnit project?

1
Any reason not to have different tasks to run the different projects? Just include the project name as a command line argument.Jon Skeet
OMG @JonSkeet! I'm sorry. Couldn't help it :) Not sure I follow. Yes, I'm thinking one step for UT another for E2E but it's multiple unit test projects and a single E2E project. Trying to figure out how to exclude the E2E one from the UT step.urig
Looks like I've hacked it. My UT projects are all called Foo.Tests.csproj but my E2E project is just called EndToEnd. I added this line to the step and it worked: projects: '**/*.Tests.csproj'. I think an even better solution might be: projects: !'**/*.EndToEnd.csproj'urig

1 Answers

1
votes

You may use projects to pick projects. I tested this against this solution and it works: enter image description here

variables:
  buildConfiguration: 'Release'
  rootDirectory: '$(Build.SourcesDirectory)/stackoverflow/69-nunit-and-xunit'

steps:

- task: DotNetCoreCLI@2
  displayName: Restore nuget packages
  inputs:
    command: restore
    projects: '**/*.csproj'
    workingDirectory: $(rootDirectory)

- task: DotNetCoreCLI@2
  displayName: Test xUnit
  inputs:
    command: test
    projects: '$(rootDirectory)/**/*XUnit.csproj'
    arguments: '--configuration $(buildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: Test NUnit
  inputs:
    command: test
    projects: '$(rootDirectory)/**/*NUnit.csproj'
    arguments: '--configuration $(buildConfiguration)'