Azure devops 不是 运行 MS 测试单元测试
Azure devops not running MS test unit tests
运行 进入 Azure Dev ops 的一个奇怪问题。我正在尝试在 Azure Dev ops 中构建我的项目。
.Net 项目结构在 VS 中如下所示:
Solution
--src
--Test
----Test Proj. 1
----Test Proj. 2
而我的 azure-pipeline.yml 看起来像这样:
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
BuildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '3.1.x'
includePreviewVersions: true
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: 'restore'
projects: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
- task: VSBuild@1
inputs:
solution: 'Project.sln'
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)'
msbuildArchitecture: x64
- task: VSTest@2
displayName: Test
inputs:
testAssemblyVer2: |
**\*.UnitTest.dll
!**\obj\**
vsTestVersion: latest
runSettingsFile: test\test.runsettings
codeCoverageEnabled: true
platform: $(BuildPlatform)
configuration: $(BuildConfiguration)
diagnosticsEnabled: true
runInParallel: true
无法找到 运行 的任何测试用例,因此在 运行 未进行任何测试的情况下完成该步骤。
这里有我遗漏的东西吗?还是我必须在配置中指定其他内容?
我的测试 project.csproj 文件包含以下内容:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CsvHelper" Version="18.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
</ItemGroup>
Azure devops not running MS test unit tests
根据您对测试文件的设置是:
**\*.UnitTest.dll
!**\obj\**
你应该确保你的测试项目的名称以.UnitTest
结尾,如Test.UnitTest
,否则生成的dll文件应该不是*.UnitTest.dll
.
要解决此问题,您可以使用 test
作为匹配关键字(确保您的测试项目名称包含 test
关键字):
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
如果以上对您没有帮助,请尝试分享您的测试项目名称和测试任务的日志。
对于那些看到这个问题不是由于路径不正确造成的线程的人:检查你是否有适合你正在使用的框架的测试适配器。在上面的例子中是 MSTest
所以 MSTest.TestAdapter
需要在每个测试项目中安装 nuget 包
运行 进入 Azure Dev ops 的一个奇怪问题。我正在尝试在 Azure Dev ops 中构建我的项目。
.Net 项目结构在 VS 中如下所示:
Solution
--src
--Test
----Test Proj. 1
----Test Proj. 2
而我的 azure-pipeline.yml 看起来像这样:
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
BuildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '3.1.x'
includePreviewVersions: true
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: 'restore'
projects: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
- task: VSBuild@1
inputs:
solution: 'Project.sln'
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)'
msbuildArchitecture: x64
- task: VSTest@2
displayName: Test
inputs:
testAssemblyVer2: |
**\*.UnitTest.dll
!**\obj\**
vsTestVersion: latest
runSettingsFile: test\test.runsettings
codeCoverageEnabled: true
platform: $(BuildPlatform)
configuration: $(BuildConfiguration)
diagnosticsEnabled: true
runInParallel: true
无法找到 运行 的任何测试用例,因此在 运行 未进行任何测试的情况下完成该步骤。
这里有我遗漏的东西吗?还是我必须在配置中指定其他内容?
我的测试 project.csproj 文件包含以下内容:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CsvHelper" Version="18.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
</ItemGroup>
Azure devops not running MS test unit tests
根据您对测试文件的设置是:
**\*.UnitTest.dll
!**\obj\**
你应该确保你的测试项目的名称以.UnitTest
结尾,如Test.UnitTest
,否则生成的dll文件应该不是*.UnitTest.dll
.
要解决此问题,您可以使用 test
作为匹配关键字(确保您的测试项目名称包含 test
关键字):
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
如果以上对您没有帮助,请尝试分享您的测试项目名称和测试任务的日志。
对于那些看到这个问题不是由于路径不正确造成的线程的人:检查你是否有适合你正在使用的框架的测试适配器。在上面的例子中是 MSTest
所以 MSTest.TestAdapter
需要在每个测试项目中安装 nuget 包