I recently started a new project using ASP.NET Core 3.1. The project consisted of am API project and a XUnit project with integration tests.
Everything was running just fine locally and I then added a YAML based Azure Pipeline for Continuous Integration. I used the standard YAML template ASP.NET Core (.NET Framework) from Azure DevOps which looks something like this.
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
The pipeline ran just fine, but to my surprise none of the tests was detected resulting in an empty resultset.
Luckily there is a quick fix. Simply add a parameter specifying which framework to use when running this tests.
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
codeCoverageEnabled: true
testAssemblyVer2: |
**\*tests.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
otherConsoleOptions: '/Framework:.NETCoreApp,Version=3.1'
Also be sure that testAssemblyVer2 matches the name of your test assemblies. In my case its **\*tests.dll
Wow, big help thanks!