-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add integration tests for third-party toolkit compatibility #34051
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
Draft
Copilot
wants to merge
3
commits into
main
Choose a base branch
from
copilot/add-integration-test-regression
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
194 changes: 194 additions & 0 deletions
194
src/TestUtils/src/Microsoft.Maui.IntegrationTests/ToolkitTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| namespace Microsoft.Maui.IntegrationTests; | ||
|
|
||
| /// <summary> | ||
| /// Integration tests that verify .NET MAUI builds successfully with popular third-party toolkit packages. | ||
| /// | ||
| /// These tests help catch regressions where MAUI changes break compatibility with widely-used community packages | ||
| /// such as CommunityToolkit.Maui and Syncfusion.Maui.Toolkit. By building template projects with these packages, | ||
| /// we ensure that MAUI's build system, MSBuild tasks, and SDK remain compatible with the broader MAUI ecosystem. | ||
| /// | ||
| /// Tests follow the same pattern as SampleTests.cs - creating projects from templates, adding package references, | ||
| /// and building to ensure no breaking changes have been introduced. | ||
| /// | ||
| /// See also: https://github.com/dotnet/maui/pull/34047 | ||
| /// </summary> | ||
| [Trait("Category", "Build")] | ||
| public class ToolkitTests : BaseTemplateTests | ||
| { | ||
| public ToolkitTests(IntegrationTestFixture fixture, ITestOutputHelper output) : base(fixture, output) { } | ||
|
|
||
| /// <summary> | ||
| /// Tests that a MAUI app can build successfully with CommunityToolkit.Maui package installed. | ||
| /// This catches regressions where MAUI changes break compatibility with the Community Toolkit. | ||
| /// </summary> | ||
| [Theory] | ||
| [InlineData("maui", DotNetCurrent, "Debug")] | ||
| [InlineData("maui", DotNetCurrent, "Release")] | ||
| public void BuildWithCommunityToolkit(string id, string framework, string config) | ||
| { | ||
| SetTestIdentifier(id, framework, config, "CommunityToolkit"); | ||
| var projectDir = TestDirectory; | ||
| var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj"); | ||
|
|
||
| // Create project from template | ||
| Assert.True(DotnetInternal.New(id, projectDir, framework, output: _output), | ||
| $"Unable to create template {id}. Check test output for errors."); | ||
|
|
||
| // Add CommunityToolkit.Maui package reference | ||
| var communityToolkitVersion = GetPackageVersion("CommunityToolkitMauiPackageVersion"); | ||
| FileUtilities.ReplaceInFile(projectFile, | ||
| "</Project>", | ||
| $""" | ||
| <ItemGroup> | ||
| <PackageReference Include="CommunityToolkit.Maui" Version="{communityToolkitVersion}" /> | ||
| </ItemGroup> | ||
| </Project> | ||
| """); | ||
|
|
||
| // Update MauiProgram.cs to use the toolkit | ||
| var mauiProgramFile = Path.Combine(projectDir, "MauiProgram.cs"); | ||
| if (File.Exists(mauiProgramFile)) | ||
| { | ||
| FileUtilities.ReplaceInFile(mauiProgramFile, | ||
| "using Microsoft.Extensions.Logging;", | ||
| """ | ||
| using Microsoft.Extensions.Logging; | ||
| using CommunityToolkit.Maui; | ||
| """); | ||
|
|
||
| FileUtilities.ReplaceInFile(mauiProgramFile, | ||
| ".UseMauiApp<App>()", | ||
| """ | ||
| .UseMauiApp<App>() | ||
| .UseMauiCommunityToolkit() | ||
| """); | ||
| } | ||
|
|
||
| // Build the project | ||
| Assert.True(DotnetInternal.Build(projectFile, config, properties: BuildProps, msbuildWarningsAsErrors: true, output: _output), | ||
| $"Project {Path.GetFileName(projectFile)} with CommunityToolkit.Maui failed to build. Check test output/attachments for errors."); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that a MAUI app can build successfully with Syncfusion.Maui.Toolkit package installed. | ||
| /// This catches regressions where MAUI changes break compatibility with Syncfusion Toolkit. | ||
| /// </summary> | ||
| [Theory] | ||
| [InlineData("maui", DotNetCurrent, "Debug")] | ||
| [InlineData("maui", DotNetCurrent, "Release")] | ||
| public void BuildWithSyncfusionToolkit(string id, string framework, string config) | ||
| { | ||
| SetTestIdentifier(id, framework, config, "SyncfusionToolkit"); | ||
| var projectDir = TestDirectory; | ||
| var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj"); | ||
|
|
||
| // Create project from template | ||
| Assert.True(DotnetInternal.New(id, projectDir, framework, output: _output), | ||
| $"Unable to create template {id}. Check test output for errors."); | ||
|
|
||
| // Add Syncfusion.Maui.Toolkit package reference | ||
| var syncfusionVersion = GetPackageVersion("SyncfusionMauiToolkitPackageVersion"); | ||
| FileUtilities.ReplaceInFile(projectFile, | ||
| "</Project>", | ||
| $""" | ||
| <ItemGroup> | ||
| <PackageReference Include="Syncfusion.Maui.Toolkit" Version="{syncfusionVersion}" /> | ||
| </ItemGroup> | ||
| </Project> | ||
| """); | ||
|
|
||
| // Update MauiProgram.cs to register Syncfusion handlers | ||
| var mauiProgramFile = Path.Combine(projectDir, "MauiProgram.cs"); | ||
| if (File.Exists(mauiProgramFile)) | ||
| { | ||
| FileUtilities.ReplaceInFile(mauiProgramFile, | ||
| "using Microsoft.Extensions.Logging;", | ||
| """ | ||
| using Microsoft.Extensions.Logging; | ||
| using Syncfusion.Maui.Toolkit.Hosting; | ||
| """); | ||
|
|
||
| FileUtilities.ReplaceInFile(mauiProgramFile, | ||
| ".UseMauiApp<App>()", | ||
| """ | ||
| .UseMauiApp<App>() | ||
| .ConfigureSyncfusionToolkit() | ||
| """); | ||
| } | ||
|
|
||
| // Build the project | ||
| Assert.True(DotnetInternal.Build(projectFile, config, properties: BuildProps, msbuildWarningsAsErrors: true, output: _output), | ||
| $"Project {Path.GetFileName(projectFile)} with Syncfusion.Maui.Toolkit failed to build. Check test output/attachments for errors."); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that a MAUI app can build successfully with both CommunityToolkit.Maui and Syncfusion.Maui.Toolkit packages. | ||
| /// This catches regressions where multiple popular toolkits conflict or where MAUI changes break multi-toolkit scenarios. | ||
| /// </summary> | ||
| [Theory] | ||
| [InlineData("maui", DotNetCurrent, "Debug")] | ||
| [InlineData("maui", DotNetCurrent, "Release")] | ||
| public void BuildWithMultipleToolkits(string id, string framework, string config) | ||
| { | ||
| SetTestIdentifier(id, framework, config, "MultipleToolkits"); | ||
| var projectDir = TestDirectory; | ||
| var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj"); | ||
|
|
||
| // Create project from template | ||
| Assert.True(DotnetInternal.New(id, projectDir, framework, output: _output), | ||
| $"Unable to create template {id}. Check test output for errors."); | ||
|
|
||
| // Add both toolkit package references | ||
| var communityToolkitVersion = GetPackageVersion("CommunityToolkitMauiPackageVersion"); | ||
| var syncfusionVersion = GetPackageVersion("SyncfusionMauiToolkitPackageVersion"); | ||
| FileUtilities.ReplaceInFile(projectFile, | ||
| "</Project>", | ||
| $""" | ||
| <ItemGroup> | ||
| <PackageReference Include="CommunityToolkit.Maui" Version="{communityToolkitVersion}" /> | ||
| <PackageReference Include="Syncfusion.Maui.Toolkit" Version="{syncfusionVersion}" /> | ||
| </ItemGroup> | ||
| </Project> | ||
| """); | ||
|
|
||
| // Update MauiProgram.cs to use both toolkits | ||
| var mauiProgramFile = Path.Combine(projectDir, "MauiProgram.cs"); | ||
| if (File.Exists(mauiProgramFile)) | ||
| { | ||
| FileUtilities.ReplaceInFile(mauiProgramFile, | ||
| "using Microsoft.Extensions.Logging;", | ||
| """ | ||
| using Microsoft.Extensions.Logging; | ||
| using CommunityToolkit.Maui; | ||
| using Syncfusion.Maui.Toolkit.Hosting; | ||
| """); | ||
|
|
||
| FileUtilities.ReplaceInFile(mauiProgramFile, | ||
| ".UseMauiApp<App>()", | ||
| """ | ||
| .UseMauiApp<App>() | ||
| .UseMauiCommunityToolkit() | ||
| .ConfigureSyncfusionToolkit() | ||
| """); | ||
| } | ||
|
|
||
| // Build the project | ||
| Assert.True(DotnetInternal.Build(projectFile, config, properties: BuildProps, msbuildWarningsAsErrors: true, output: _output), | ||
| $"Project {Path.GetFileName(projectFile)} with multiple toolkits failed to build. Check test output/attachments for errors."); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Helper method to read package versions from Versions.props | ||
| /// </summary> | ||
| private string GetPackageVersion(string propertyName) | ||
| { | ||
| var versionsPropsPath = Path.Combine(TestEnvironment.GetMauiDirectory(), "eng", "Versions.props"); | ||
| var versionsProps = System.Xml.Linq.XDocument.Load(versionsPropsPath); | ||
| var version = versionsProps.Descendants(propertyName).FirstOrDefault()?.Value; | ||
|
|
||
| if (string.IsNullOrEmpty(version)) | ||
| throw new Exception($"Could not find {propertyName} in Versions.props"); | ||
|
|
||
| return version; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think building a project with the package will help avoid the breaking change with
InternalVisibleTo. Since the toolkit version will likely target an older version of MAUI than the CI one, it will always build but will cause runtime errors only.Would creating a sample with several toolkit controls help in some way ?
Just to ensure that the app can build and at least display the first page with various controls without crashing?