Skip to content
Open
Show file tree
Hide file tree
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 May 4, 2026
0d6a790
Comment out macOS/MacCatalyst tests and fix test verb workaround
jonathanpeppers May 5, 2026
3eac4e9
Bump Microsoft.Tools.Mlaunch to 1.1.115
jonathanpeppers May 12, 2026
e086c8e
Split dotnet test into build + ComputeRunArguments + test --no-build
jonathanpeppers May 13, 2026
062cf27
Remove ComputeRunArguments diagnostic step
jonathanpeppers May 14, 2026
6f672aa
Set UseFloatingTargetPlatformVersion in csproj for dotnet test
jonathanpeppers May 14, 2026
612099d
Use Execution.RunAsync directly for dotnet test step
jonathanpeppers May 14, 2026
b4c7370
Drop --no-build and use dotnet test directly
jonathanpeppers May 14, 2026
69e617e
Remove unnecessary env var overrides from dotnet test call
jonathanpeppers May 14, 2026
1f8941c
Clear MSBuild env vars for dotnet test call
jonathanpeppers May 15, 2026
167accd
Add /bl: to dotnet test for CI diagnostics
jonathanpeppers May 18, 2026
7fc6857
Boot simulator before running dotnet test
jonathanpeppers May 27, 2026
7fb2b4f
Fix NUnit v4 Assert.That syntax in DotNetTestTest
jonathanpeppers May 28, 2026
b42f06c
Use xcrun simctl to find simulators instead of MSBuild target
jonathanpeppers May 28, 2026
73284a3
Add dotnet test integration tests for all Apple platforms
jonathanpeppers May 4, 2026
0adc863
Comment out macOS/MacCatalyst tests and fix test verb workaround
jonathanpeppers May 5, 2026
d2e9c04
Bump Microsoft.Tools.Mlaunch to 1.1.115
jonathanpeppers May 12, 2026
405c7d1
Split dotnet test into build + ComputeRunArguments + test --no-build
jonathanpeppers May 13, 2026
8ad0a51
Remove ComputeRunArguments diagnostic step
jonathanpeppers May 14, 2026
f37bce4
Set UseFloatingTargetPlatformVersion in csproj for dotnet test
jonathanpeppers May 14, 2026
21ecf43
Use Execution.RunAsync directly for dotnet test step
jonathanpeppers May 14, 2026
7fe9af1
Drop --no-build and use dotnet test directly
jonathanpeppers May 14, 2026
fa4dd91
Remove unnecessary env var overrides from dotnet test call
jonathanpeppers May 14, 2026
9ff4b41
Clear MSBuild env vars for dotnet test call
jonathanpeppers May 15, 2026
2fc5782
Add /bl: to dotnet test for CI diagnostics
jonathanpeppers May 18, 2026
68e2a94
Boot simulator before running dotnet test
jonathanpeppers May 27, 2026
a0a3853
Fix NUnit v4 Assert.That syntax in DotNetTestTest
jonathanpeppers May 28, 2026
3cc98e3
Use xcrun simctl to find simulators instead of MSBuild target
jonathanpeppers May 28, 2026
5806d5b
Merge commit 'b42f06ca91f4e3ff72dcf6fd8c50bf441df63db7' into jonathan…
jonathanpeppers Jun 3, 2026
9b5a79d
Create simulator device if none exist on CI
jonathanpeppers Jun 3, 2026
bab0fc5
Pass the device to 'dotnet test'.
rolfbjarne Jun 5, 2026
5c26de0
Use Xamarin.MacDev APIs for simulator management in DotNetTestTest
rolfbjarne Jun 5, 2026
c654353
Only boot the simulator if it's not already booted
rolfbjarne Jun 5, 2026
c13d1ac
Merge branch 'net11.0' into jonathanpeppers/add-mlaunch-mtp-tests
rolfbjarne Jun 16, 2026
49cb27a
Merge branch 'net11.0' into jonathanpeppers/add-mlaunch-mtp-tests
rolfbjarne Jun 19, 2026
f16e7f4
Merge branch 'net11.0' into jonathanpeppers/add-mlaunch-mtp-tests
rolfbjarne Jun 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mk/xamarin.mk
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
15 changes: 10 additions & 5 deletions tests/common/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public static ExecutionResult Execute (string verb, string project, Dictionary<s
case "publish":
case "restore":
case "run":
case "test":
var args = new List<string> ();
args.Add (verb);
args.Add (project);
Expand Down Expand Up @@ -304,11 +305,15 @@ public static ExecutionResult Execute (string verb, string project, Dictionary<s
Console.WriteLine ($"Binlog: {binlogPath}");

// Work around https://github.com/dotnet/msbuild/issues/8845
args.Add ("/v:diag");
args.Add ("/consoleloggerparameters:Verbosity=Quiet");
// vb does not have preview lang, so we force it to latest
if (project.EndsWith (".vbproj", StringComparison.OrdinalIgnoreCase))
args.Add ("/p:LangVersion=latest");
// Skip these for 'dotnet test' because they leak through '-- ' in
// RunArguments and get passed to the test runner as app arguments.
if (verb != "test") {
args.Add ("/v:diag");
args.Add ("/consoleloggerparameters:Verbosity=Quiet");
// vb does not have preview lang, so we force it to latest
if (project.EndsWith (".vbproj", StringComparison.OrdinalIgnoreCase))
args.Add ("/p:LangVersion=latest");
}
// End workaround

if (msbuildParallelism.HasValue) {
Expand Down
114 changes: 114 additions & 0 deletions tests/dotnet/UnitTests/DotNetTestTest.cs
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")]
Comment thread
jonathanpeppers marked this conversation as resolved.
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!;
}
}
}
6 changes: 3 additions & 3 deletions tests/dotnet/UnitTests/DotNetUnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@
<Compile Include="..\..\common\BinLog.cs">
<Link>external\BinLog.cs</Link>
</Compile>
<Compile Include="..\..\..\external\Xamarin.MacDev\Xamarin.MacDev\PListObject.cs">
<Link>external\PListObject.cs</Link>
</Compile>
<Compile Include="..\..\..\tools\common\SdkVersions.cs">
<Link>external\SdkVersions.cs</Link>
</Compile>
Expand Down Expand Up @@ -85,6 +82,9 @@
<ItemGroup>
<Folder Include="external\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\external\Xamarin.MacDev\Xamarin.MacDev\Xamarin.MacDev.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="System.Text.Json" />
</ItemGroup>
Expand Down
Loading