Skip to content

[dotnet] Add test project templates for all Apple platforms#25195

Merged
rolfbjarne merged 17 commits intonet11.0from
jonathanpeppers/apple-test-templates
Apr 28, 2026
Merged

[dotnet] Add test project templates for all Apple platforms#25195
rolfbjarne merged 17 commits intonet11.0from
jonathanpeppers/apple-test-templates

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

@jonathanpeppers jonathanpeppers commented Apr 20, 2026

Summary

Add dotnet new test project templates for all Apple platforms, equivalent to what was done for Android in dotnet/android@885dd60.

Modeled after jonathanpeppers/iOSDotNetTest.

New templates

Short name Platform TFM
iostest iOS net10.0-ios
maccatalysttest Mac Catalyst net10.0-maccatalyst
tvostest tvOS net10.0-tvos
macostest macOS net10.0-macos

Usage:

dotnet new iostest -n MyTests
dotnet run --project MyTests

Each template creates an MSTest-based test project that runs tests inside the proper UIKit/AppKit run loop, displaying results in a native UI. This is needed because Apple platform tests must run inside a real application process.

Key design decisions

  • Platform-appropriate entry points: iOS and Mac Catalyst use the UIKit SceneDelegate pattern. tvOS uses the older AppDelegate+Window pattern (no SceneDelegate support). macOS uses AppKit with NSApplication.
  • MtouchInterpreter=all set globally: Instead of setting this workaround in each template, it is now set in Xamarin.Shared.props when EnableMSTestRunner=true, so any MSTest runner project on Apple platforms automatically gets the interpreter enabled.
  • GenerateTestingPlatformEntryPoint=false: Required because our templates provide a custom Main() entry point and MSTest SDK would otherwise generate a conflicting one.
  • Template tests updated: Added all 4 templates to TemplateTest.cs to verify they build correctly.

@jonathanpeppers
Copy link
Copy Markdown
Member Author

I'm still testing this, I don't like the GetResults target, for example and there is logic in the template that should be in the workload.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

jonathanpeppers and others added 3 commits April 20, 2026 16:29
Add iostest, maccatalysttest, tvostest, and macostest project templates
that create MSTest-based test projects for each Apple platform. These
are modeled after jonathanpeppers/iOSDotNetTest and the equivalent
androidtest template in dotnet/android.

Each template includes:
- MSTest runner with custom entry point (Main.cs)
- ResultConsumer for test result tracking and TRX reporting
- Sample Test1.cs with pass/fail/skip examples
- Platform-appropriate Info.plist and Entitlements.plist
- global.json for Microsoft.Testing.Platform configuration
- MtouchInterpreter=all workaround for AOT compilation issues

Platform-specific details:
- iOS/MacCatalyst: UIApplication.Main with SceneDelegate pattern
- tvOS: UIApplication.Main with AppDelegate Window pattern
- macOS: NSApplication with AppKit (NSWindow/NSTextField)

Also updates TemplateTest.cs to include the 4 new templates in the
test matrix so they are validated by CreateAndBuildProjectTemplate.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the MtouchInterpreter workaround from individual test templates
into Xamarin.Shared.props so any MSTest runner project automatically
gets the interpreter enabled, not just our templates.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers force-pushed the jonathanpeppers/apple-test-templates branch from 40706ed to cac67af Compare April 20, 2026 21:29
@jonathanpeppers jonathanpeppers changed the base branch from main to net11.0 April 20, 2026 21:29
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
Copy link
Copy Markdown
Member

There's a warning when building the tvOS test template:

This call site is reachable on: 'tvOS' 13.0 and later. 'UIWindow' is obsoleted on: 'tvos' 26.0 and later (Use the 'UIWindowScene' overload instead.).

There's also a number of warnings when building a maccatalyst template - but not the new one, so it feels unrelated, but on the other hand it's not a problem I've seen before, and it's too much of a coincidence that it happens in a PR that adds new templates...

Xamarin.Tests.TemplateTest.CreateAndBuildProjectTemplate(maccatalysttest-csharp): Build warnings:
    Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.ReflectionCredentialEnvelope.AzureCore.BuildDelegateAccessTokenToAuthToken(): Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
    Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.ReflectionCredentialEnvelope.AzureCore.BuildDelegateAccessTokenToAuthToken(): Using member 'System.Linq.Expressions.Expression.Property(Expression, String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Creating Expressions requires unreferenced code because the members being referenced by the Expression may be trimmed.
    Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.ReflectionCredentialEnvelope.AzureCore.BuildDelegateAccessTokenToAuthToken(): Using member 'System.Linq.Expressions.Expression.Property(Expression, String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Creating Expressions requires unreferenced code because the members being referenced by the Expression may be trimmed.
[...]

@jonathanpeppers
Copy link
Copy Markdown
Member Author

It seems like the dotnet new tvos template has the same warning about UIWindow. I could fix it in both templates, but I don't have a device to manually test it stil works.

ApplicationInsights is a dependency of MSTest and AppInsights has trimmer warnings. Copilot says MacCatalyst is doing SdkOnly mode, and the other platforms None -- I could make $(EnableMSTestRunner) default to $(SuppressTrimAnalysisWarnings)=true for now?

MSTest's transitive dependency on Microsoft.ApplicationInsights
produces trimmer warnings on Mac Catalyst where linking defaults
to SdkOnly. These warnings are not actionable for test projects.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Remove UIWindow construction and UI setup — the existing tvOS template
does not construct UIWindow. Also match the Window property style and
remove unused StatusChanged event.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #a3dc29b] Build passed (Build packages) ✅

Pipeline on Agent
Hash: a3dc29b2907d73b4a7c122b27e2293a18cc69ff2 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #a3dc29b] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: a3dc29b2907d73b4a7c122b27e2293a18cc69ff2 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: a3dc29b2907d73b4a7c122b27e2293a18cc69ff2 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #a3dc29b] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: a3dc29b2907d73b4a7c122b27e2293a18cc69ff2 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne merged commit fc04aba into net11.0 Apr 28, 2026
15 checks passed
@rolfbjarne rolfbjarne deleted the jonathanpeppers/apple-test-templates branch April 28, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants