-
Notifications
You must be signed in to change notification settings - Fork 570
Add dotnet test integration tests for all Apple platforms
#25320
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
Open
jonathanpeppers
wants to merge
36
commits into
net11.0
Choose a base branch
from
jonathanpeppers/add-mlaunch-mtp-tests
base: net11.0
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.
+128
−9
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
a5f1992
Add dotnet test integration tests for all Apple platforms
jonathanpeppers 0d6a790
Comment out macOS/MacCatalyst tests and fix test verb workaround
jonathanpeppers 3eac4e9
Bump Microsoft.Tools.Mlaunch to 1.1.115
jonathanpeppers e086c8e
Split dotnet test into build + ComputeRunArguments + test --no-build
jonathanpeppers 062cf27
Remove ComputeRunArguments diagnostic step
jonathanpeppers 6f672aa
Set UseFloatingTargetPlatformVersion in csproj for dotnet test
jonathanpeppers 612099d
Use Execution.RunAsync directly for dotnet test step
jonathanpeppers b4c7370
Drop --no-build and use dotnet test directly
jonathanpeppers 69e617e
Remove unnecessary env var overrides from dotnet test call
jonathanpeppers 1f8941c
Clear MSBuild env vars for dotnet test call
jonathanpeppers 167accd
Add /bl: to dotnet test for CI diagnostics
jonathanpeppers 7fc6857
Boot simulator before running dotnet test
jonathanpeppers 7fb2b4f
Fix NUnit v4 Assert.That syntax in DotNetTestTest
jonathanpeppers b42f06c
Use xcrun simctl to find simulators instead of MSBuild target
jonathanpeppers 73284a3
Add dotnet test integration tests for all Apple platforms
jonathanpeppers 0adc863
Comment out macOS/MacCatalyst tests and fix test verb workaround
jonathanpeppers d2e9c04
Bump Microsoft.Tools.Mlaunch to 1.1.115
jonathanpeppers 405c7d1
Split dotnet test into build + ComputeRunArguments + test --no-build
jonathanpeppers 8ad0a51
Remove ComputeRunArguments diagnostic step
jonathanpeppers f37bce4
Set UseFloatingTargetPlatformVersion in csproj for dotnet test
jonathanpeppers 21ecf43
Use Execution.RunAsync directly for dotnet test step
jonathanpeppers 7fe9af1
Drop --no-build and use dotnet test directly
jonathanpeppers fa4dd91
Remove unnecessary env var overrides from dotnet test call
jonathanpeppers 9ff4b41
Clear MSBuild env vars for dotnet test call
jonathanpeppers 2fc5782
Add /bl: to dotnet test for CI diagnostics
jonathanpeppers 68e2a94
Boot simulator before running dotnet test
jonathanpeppers a0a3853
Fix NUnit v4 Assert.That syntax in DotNetTestTest
jonathanpeppers 3cc98e3
Use xcrun simctl to find simulators instead of MSBuild target
jonathanpeppers 5806d5b
Merge commit 'b42f06ca91f4e3ff72dcf6fd8c50bf441df63db7' into jonathan…
jonathanpeppers 9b5a79d
Create simulator device if none exist on CI
jonathanpeppers bab0fc5
Pass the device to 'dotnet test'.
rolfbjarne 5c26de0
Use Xamarin.MacDev APIs for simulator management in DotNetTestTest
rolfbjarne c654353
Only boot the simulator if it's not already booted
rolfbjarne c13d1ac
Merge branch 'net11.0' into jonathanpeppers/add-mlaunch-mtp-tests
rolfbjarne 49cb27a
Merge branch 'net11.0' into jonathanpeppers/add-mlaunch-mtp-tests
rolfbjarne f16e7f4
Merge branch 'net11.0' into jonathanpeppers/add-mlaunch-mtp-tests
rolfbjarne 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
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # Available versions can be seen here: | ||
| # https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-eng/NuGet/Microsoft.Tools.Mlaunch/versions | ||
| MLAUNCH_NUGET_VERSION=1.1.113 | ||
| MLAUNCH_NUGET_VERSION=1.1.115 | ||
| # https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-eng/NuGet/AppleDocReader/versions | ||
| ADR_NUGET_VERSION=1.0.0 |
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
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,114 @@ | ||
| using System.Linq; | ||
|
|
||
| using Xamarin.MacDev; | ||
| using Xamarin.MacDev.Models; | ||
| using Xamarin.Tests; | ||
| using Xamarin.Utils; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Xamarin.Tests { | ||
| [TestFixture] | ||
| public class DotNetTestTest : TestBaseClass { | ||
| [Test] | ||
| [TestCase (ApplePlatform.iOS, "iostest")] | ||
| [TestCase (ApplePlatform.TVOS, "tvostest")] | ||
| // macOS and Mac Catalyst don't use mlaunch (they use 'open' via Desktop.targets), | ||
| // so MTP support requires a different approach for these platforms. | ||
| // [TestCase (ApplePlatform.MacCatalyst, "maccatalysttest")] | ||
| // [TestCase (ApplePlatform.MacOSX, "macostest")] | ||
| public void DotNetTest (ApplePlatform platform, string template) | ||
| { | ||
| Configuration.IgnoreIfIgnoredPlatform (platform); | ||
|
|
||
| var tmpDir = Cache.CreateTemporaryDirectory (); | ||
| var outputDir = Path.Combine (tmpDir, template); | ||
| DotNet.AssertNew (outputDir, template); | ||
| var proj = Path.Combine (outputDir, $"{template}.csproj"); | ||
|
|
||
| // Boot a simulator so that ComputeRunArguments can find a device | ||
| var log = ConsoleLogger.Instance; | ||
| var simService = new SimulatorService (log); | ||
| var runtimeService = new RuntimeService (log); | ||
| var device = GetOrCreateDevice (platform, simService, runtimeService); | ||
|
|
||
| if (!device.IsBooted) | ||
| Assert.That (simService.Boot (device.Udid), Is.True, $"Failed to boot simulator {device.Udid}."); | ||
|
|
||
| try { | ||
| // dotnet test internally calls ComputeRunArguments via MSBuild API without | ||
| // forwarding /p: properties, so we must set them in the project file directly. | ||
| var csproj = File.ReadAllText (proj); | ||
| csproj = csproj.Replace ( | ||
| "</PropertyGroup>", | ||
| $" <UseFloatingTargetPlatformVersion>true</UseFloatingTargetPlatformVersion>\n <Device>{device.Udid}</Device>\n </PropertyGroup>"); | ||
| File.WriteAllText (proj, csproj); | ||
|
|
||
| // Replace generated tests with a single passing test | ||
| var testFile = Path.Combine (outputDir, "Test1.cs"); | ||
| File.WriteAllText (testFile, $@"namespace {template}; | ||
|
|
||
| [TestClass] | ||
| public sealed class Test1 {{ | ||
| [TestMethod] | ||
| public void TestMethod1 () | ||
| {{ | ||
| }} | ||
| }} | ||
| "); | ||
|
|
||
| // Run 'dotnet test' directly using Execution.RunAsync. | ||
| // dotnet test's MTP flow doesn't forward /p: properties to its internal | ||
| // ComputeRunArguments MSBuild API call, so properties must be in the csproj. | ||
| var env = new Dictionary<string, string?> (); | ||
| env ["MSBuildSDKsPath"] = null; | ||
| env ["MSBUILD_EXE_PATH"] = null; | ||
| var binlog = Path.Combine (outputDir, "log-test.binlog"); | ||
| var testArgs = new List<string> { "test", proj, $"/bl:{binlog}" }; | ||
| var testResult = Execution.RunAsync (DotNet.Executable, testArgs, env, Console.Out, workingDirectory: outputDir, timeout: TimeSpan.FromMinutes (10)).Result; | ||
| Assert.That (testResult.ExitCode, Is.EqualTo (0), $"'dotnet test' failed with exit code {testResult.ExitCode}.\nBinlog: {binlog}\nOutput:\n{testResult.Output.MergedOutput}"); | ||
| } finally { | ||
| simService.Shutdown (device.Udid); | ||
| } | ||
| } | ||
|
|
||
| static SimulatorDeviceInfo GetOrCreateDevice (ApplePlatform platform, SimulatorService simService, RuntimeService runtimeService) | ||
| { | ||
| var runtimePlatform = platform switch { | ||
| ApplePlatform.iOS => "iOS", | ||
| ApplePlatform.TVOS => "tvOS", | ||
| _ => throw new ArgumentException ($"Unsupported platform: {platform}"), | ||
| }; | ||
|
|
||
| // Find an existing available device for this platform | ||
| var devices = simService.List (availableOnly: true); | ||
| var platformDevices = devices | ||
| .Where (d => string.Equals (d.Platform, runtimePlatform, StringComparison.OrdinalIgnoreCase)) | ||
| .OrderByDescending (d => d.OSVersion) | ||
| .ToList (); | ||
|
|
||
| if (platformDevices.Count > 0) | ||
| return platformDevices [0]; | ||
|
|
||
| // No devices exist — find the best runtime and create one | ||
| var runtimes = runtimeService.ListByPlatform (runtimePlatform, availableOnly: true); | ||
| Assert.That (runtimes, Is.Not.Empty, $"No available {runtimePlatform} simulator runtimes found."); | ||
|
|
||
| var bestRuntime = runtimes.OrderByDescending (r => r.Version).First (); | ||
|
|
||
| var defaultDeviceType = platform switch { | ||
| ApplePlatform.iOS => "com.apple.CoreSimulator.SimDeviceType.iPhone-16", | ||
| ApplePlatform.TVOS => "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-3rd-generation-4K", | ||
| _ => throw new ArgumentException ($"Unsupported platform: {platform}"), | ||
| }; | ||
|
|
||
| var udid = simService.Create ("test-device", defaultDeviceType, bestRuntime.Identifier); | ||
| Assert.That (udid, Is.Not.Null, $"Failed to create {runtimePlatform} simulator device."); | ||
|
|
||
| // Re-fetch the device info so we have the full object | ||
| var created = simService.List (availableOnly: true).FirstOrDefault (d => d.Udid == udid); | ||
| Assert.That (created, Is.Not.Null, $"Created simulator {udid} not found in device list."); | ||
| return created!; | ||
| } | ||
| } | ||
| } | ||
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
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.