Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Use dotnet test for running unit tests #19172

Merged
merged 11 commits into from
Jan 17, 2025
49 changes: 15 additions & 34 deletions build/ci/.azure-devops-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@ jobs:
UWP:
UNO_UWP_BUILD: true
XAML_FLAVOR_BUILD: UWP
ADDITIONAL_FLAGS: ''

WinUI:
UNO_UWP_BUILD: false
XAML_FLAVOR_BUILD: WinUI
ADDITIONAL_FLAGS: ''

# Keep for future previews
# Preview:
# ADDITIONAL_FLAGS: '/p:LangVersion=preview /p:MicrosoftNetCompilerVersionOverride=3.8.0-3.final'

#CSharp9:
# ADDITIONAL_FLAGS: '/p:LangVersion=9.0'

variables:
CombinedConfiguration: Release|Any CPU
Expand Down Expand Up @@ -77,10 +68,9 @@ jobs:
cleanDestinationFolder: false
overwriteExistingFiles: true

- task: MSBuild@1
inputs:
solution: src/Uno.UI-UnitTests-only.slnf
msbuildArguments: /r /v:m /p:CheckExclusions=True /p:Configuration=Release /nodeReuse:true /detailedsummary /m $(ADDITIONAL_FLAGS) /bl:$(build.artifactstagingdirectory)\unit-tests-build-$(XAML_FLAVOR_BUILD).binlog
- pwsh: |
dotnet build src/Uno.UI-UnitTests-only.slnf -c Release -bl:$(build.artifactstagingdirectory)\unit-tests-build-$(XAML_FLAVOR_BUILD).binlog
displayName: Build unit tests solution filter

- task: PublishBuildArtifacts@1
condition: always()
Expand All @@ -90,26 +80,17 @@ jobs:
ArtifactName: NugetPackages-Artifacts
ArtifactType: Container

- task: VisualStudioTestPlatformInstaller@1
inputs:
versionSelector: specificVersion
testPlatformVersion: 17.6.0
- pwsh: |
dotnet test src/Uno.UI-UnitTests-only.slnf -c Release --no-build -- --report-trx --results-directory $(Build.SourcesDirectory)/artifacts/TestResults
displayName: Run unit tests

- task: VSTest@2
- task: PublishTestResults@2
displayName: Publish TRX Test Results
inputs:
testAssemblyVer2: |
**\*test*.dll
!**\obj\**
!**\*Wasm.Test*.dll
!**\*UITests.dll
!**\*.RuntimeTests.dll
!**\Uno.UI.Tests.ViewLibraryProps.dll
!**\Uno.UI.Tests.ViewLibrary.dll
!**\testhost*.*
!**\Microsoft*.dll

vsTestVersion: toolsInstaller
testRunTitle: $(Agent.JobName)
testSelector: testAssemblies
batchingBasedOnAgentsOption: customBatchSize
customBatchSizeValue: 200 # test count / 10 (https://developercommunity.visualstudio.com/content/problem/891803/vstestconsoleadapter-fails-with-outofmemory.html?childToView=896206#comment-896206)
testResultsFormat: 'VSTest'
testResultsFiles: '*.trx'
searchFolder: '$(Build.SourcesDirectory)/artifacts/TestResults'
testRunTitle: 'Unit Tests $(XAML_FLAVOR_BUILD)'
mergeTestResults: true
continueOnError: true
condition: always()
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@

<PropertyGroup>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
<UnoDisableNetAnalyzers Condition="$(MSBuildProjectName.Contains('Test'))">true</UnoDisableNetAnalyzers>
<IsSampleProject>$(MSBuildProjectName.Contains('Sample'))</IsSampleProject>
<IsSampleProject Condition="'$(IsSampleProject)'=='false'">$(MSBuildProjectName.Contains('UnoIslands'))</IsSampleProject>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
20 changes: 16 additions & 4 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Product>$(AssemblyName) $(TargetFramework)</Product>
<Product Condition="'$(UnoRuntimeIdentifier)' != ''">$(AssemblyName) ($(TargetFramework) $(UnoRuntimeIdentifier))</Product>
<CommunityToolkitMvvmVersion>8.2.2</CommunityToolkitMvvmVersion>
<TestingPlatformDotNetTestSupport Condition="'$(IsTestingPlatformApplication)' == 'true'">true</TestingPlatformDotNetTestSupport>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -61,6 +62,15 @@
</Target>

<PropertyGroup>
<!-- IMPORTANT!!! KEEP BOTH MSTest and MTP versions in sync -->
<!-- For a given MSTest version, go to https://www.nuget.org/packages/MSTest.TestAdapter/3.7.1#dependencies-body-tab -->
<!-- (replacing 3.7.1 in the url with the MSTest version in question) -->
<!-- And look for MTP version in there, and make sure MicrosoftTestingPlatformVersion is the same -->
<!-- Alternatively, migrate to MSTest.Sdk and let it handle the MTP versioning for you -->
<!-- In case of MSTest.Sdk, the TrxReport package will not be needed. It will be added automatically -->
<MSTestVersion>3.7.1</MSTestVersion>
<MicrosoftTestingPlatformVersion>1.5.1</MicrosoftTestingPlatformVersion>

<SkiaSharpVersion>2.88.7</SkiaSharpVersion>
<!-- TODO: Uncomment when we're net8.0+ to have SamplesApp serve as a good test for SkiaSharp 3 support -->
<!-- <SkiaSharpVersion Condition="'$(IsTestProject)' == 'true' or '$(IsSampleProject)' == 'true'">3.0.0-preview.3.1</SkiaSharpVersion> -->
Expand All @@ -76,10 +86,12 @@
<PackageReference Update="Uno.Core.Extensions.Compatibility" Version="4.0.1" />
<PackageReference Update="Uno.Diagnostics.Eventing" Version="2.0.1" />
<PackageReference Update="Uno.Wasm.Bootstrap" Version="9.0.8" />
<PackageReference Update="MSTest" Version="3.7.1" />
<PackageReference Update="MSTest.TestFramework" Version="3.7.1" />
<PackageReference Update="MSTest.TestAdapter" Version="3.7.1" />
<PackageReference Update="MSTest.Analyzers" Version="3.7.1" />
<PackageReference Update="MSTest" Version="$(MSTestVersion)" />
<PackageReference Update="MSTest.TestFramework" Version="$(MSTestVersion)" />
<PackageReference Update="MSTest.TestAdapter" Version="$(MSTestVersion)" />
<PackageReference Update="MSTest.Analyzers" Version="$(MSTestVersion)" />
<PackageReference Update="Microsoft.Testing.Extensions.TrxReport" Version="$(MicrosoftTestingPlatformVersion)" />

<PackageReference Update="Uno.MonoAnalyzers" Version="1.0.0" PrivateAssets="all" />
<PackageReference Update="Uno.Wasm.WebSockets" Version="1.1.0" />
<PackageReference Update="Microsoft.TypeScript.MSBuild" Version="4.3.5" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ namespace Uno.UI.SourceGenerators.Tests.MetadataUpdateTests;
[TestClass]
public class Given_HotReloadService
{
[DataTestMethod]
[TestMethod]
[DynamicData(nameof(GetScenarios), DynamicDataSourceType.Method)]
// Failed HR Uno.UI.SourceGenerators.Tests.MetadataUpdateTests.Given_HotReloadService.HR
// Assert.AreEqual failed.
// Expected:<0>. Actual:<1>.
// Diagnostics: warning CS1701: Assuming assembly reference 'System.ObjectModel, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' used by 'Uno.UI' matches identity 'System.ObjectModel, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' of 'System.ObjectModel', you may need to supply runtime policy, expected
[Ignore("Needs investigation")]
MartinZikmund marked this conversation as resolved.
Show resolved Hide resolved
public async Task HR(string name, Scenario? scenario, Project[]? projects)
{
if (scenario != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

<ItemGroup>
<PackageReference Include="MSTest" />
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.12.0-3.final" />
<PackageReference Include="Microsoft.CodeAnalysis.Features" Version="4.12.0-3.final" />
Expand Down
1 change: 1 addition & 0 deletions src/Uno.Analyzers.Tests/Uno.Analyzers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<ItemGroup>
<PackageReference Include="MSTest" />
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="$(CodeAnalysisVersionForAnalyzersTests)" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(CodeAnalysisVersionForAnalyzersTests)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(CodeAnalysisVersionForAnalyzersTests)" />
Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI.Tests/Uno.UI.Unit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="MSTest" />
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Moq" Version="4.17.2" />
<PackageReference Include="Uno.Core.Extensions.Logging.Singleton" Version="4.0.0-dev.7" PrivateAssets="all" />
Expand Down
Loading