【发布时间】:2021-12-16 11:05:00
【问题描述】:
我正在尝试运行一些自动化测试作为构建管道的一部分,但一直没有返回任何结果。我的测试文件通常看起来像“ApiTests”或“UITests”。我试图通过查找文件的“测试”部分来定位它们。但是,我在自动测试运行程序中不断收到此消息:测试运行检测到为不同框架和平台版本构建的 DLL。以下 DLL 与当前设置不匹配,即 .NETFramework、Version=v4.0 框架和 X86 平台。 根据 csproj 文件,我的版本是 3.1。 这是 YAML 目前的样子:
# 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:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: UseDotNet@2
displayName: 'Install .NET Core SDK'
inputs:
version: 3.0.x
performMultiLevelLookup: true
- 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)'
msbuildArchitecture: 'x64'
- task: VSTest@2
displayName: 'Automated Tests'
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
testFiltercriteria: '/Tests:Tests'
uiTests: true
runTestsInIsolation: true
codeCoverageEnabled: true
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
我的文件通常命名为:AppsSigninTests.cs
我的实际测试看起来像这样:
[Fact]
public void SomethingSomethingSomething()
{
//Test Code Here
}
我应该在测试标题的末尾添加“测试”吗?我错过了什么让 YAML 错过了这些测试?
编辑 我现在已经到了可以找到文件但没有运行实际测试的地步(仍然没有显示结果)。现在是 YAML:
# 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:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
#- task: UseDotNet@2
#displayName: 'Install .NET Core SDK'
#inputs:
#version: 3.0.x
#performMultiLevelLookup: true
- 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
displayName: 'Automated Tests'
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
AutomatedRegression.csproj
!**\*TestAdapter.dll
!**\obj\**
#**\*test*.dll
searchFolder: '$(System.DefaultWorkingDirectory)'
testFiltercriteria: '/Tests:VerySpecificNameOfTest'
uiTests: true
runTestsInIsolation: true
codeCoverageEnabled: true
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
test.dll 行似乎成功了,所以 yaml 找不到我要的文件。但我担心它会阻止测试实际运行。 VSTest 任务的输出是这样的:总共有 1 个测试文件与指定的模式匹配。 但后来它说:Publishing test results: 0 然后运行后的Tests选项卡没有结果也没有运行测试
【问题讨论】:
-
您的测试项目是否针对 .net 核心?从消息来看,它听起来像是针对 .net 框架。
-
@Connell.O'Donnell 它看起来像是针对 .net 框架,它应该针对 .net 代码吗?
-
$(buildPlatform)的值是多少?如果是 x64,何不试试 x86。 -
@Connell.O'Donnell 目前是“任何 CPU”,将其更改为 x86。现在我遇到了这个问题:##[warning]No test sources found matching the given filter '**test.dll,!***TestAdapter.dll,!**\obj**'
-
为了调试这个,我建议添加一个 powershell 任务来告诉你测试结果文件是否存在,以及它包含什么。您可以稍后删除该任务。
标签: c# azure automation yaml azure-pipelines