Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions dotnet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ $(1)_NUGET_TARGETS = \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Xamarin.Shared.Sdk.TargetFrameworkInference.props \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Xamarin.Shared.Sdk.props \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Xamarin.Shared.Sdk.Trimming.props \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Xamarin.Shared.Sdk.MSTest.props \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Xamarin.Shared.Sdk.targets \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/dotnet-xcsync.targets \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Microsoft.MaciOS.Sdk.Xcode.targets \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"symbols/bundleId/description": "Overrides the ApplicationId in the project file",
"symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "Microsoft",
"classifications": [ "macOS", "Mac Catalyst", "Test" ],
"groupIdentity": "Microsoft.MacCatalyst.MacCatalystTest",
"identity": "Microsoft.MacCatalyst.MacCatalystTest.CSharp",
"name": "Mac Catalyst Test Project",
"description": "A project for creating a .NET Mac Catalyst test project using MSTest",
"shortName": "maccatalysttest",
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "MacCatalystTest1",
"sources": [
{
"source": "./",
"target": "./"
}
],
"preferNameDirectory": true,
"primaryOutputs": [
{ "path": "MacCatalystTest1.csproj" }
],
"symbols": {
"bundleId": {
"type": "parameter",
"description": "Overrides the ApplicationId in the project file",
"datatype": "string",
"replaces": "com.companyname.MacCatalystTest1"
},
"minOSVersion": {
"type": "parameter",
"description": "Overrides SupportedOSPlatformVersion in the project file",
"replaces": "minOSVersion",
"datatype": "string",
"defaultValue": "17.0"
}
},
"defaultName": "MacCatalystTest1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>MacCatalystTest1</string>
<key>CFBundleIdentifier</key>
<string>com.companyname.MacCatalystTest1</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>UIDeviceFamily</key>
<array>
<integer>2</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net11.0-maccatalyst</TargetFramework>
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">MacCatalystTest1</RootNamespace>
Comment thread
jonathanpeppers marked this conversation as resolved.
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings>
<EnableMSTestRunner>true</EnableMSTestRunner>
<SupportedOSPlatformVersion>minOSVersion</SupportedOSPlatformVersion>
<ApplicationId>com.companyname.MacCatalystTest1</ApplicationId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest" Version="4.2.1" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System.Diagnostics;
using Microsoft.Testing.Extensions;
using Microsoft.Testing.Platform.Builder;
using Microsoft.Testing.Platform.Extensions;
using Microsoft.Testing.Platform.Extensions.Messages;
using MacCatalystTest1;

[assembly: Parallelize (Scope = ExecutionScope.MethodLevel)]

// UIApplication.Main() provides a proper UIKit run loop,
// preventing watchdog kills during long test runs.
UIApplication.Main (args, null, typeof (AppDelegate));

[Register ("AppDelegate")]
class AppDelegate : UIApplicationDelegate {
public override UISceneConfiguration GetConfiguration (UIApplication application,
UISceneSession connectingSceneSession, UISceneConnectionOptions options)
{
return new UISceneConfiguration ("Default Configuration", connectingSceneSession.Role);
}
}

[Register ("SceneDelegate")]
class SceneDelegate : UIResponder, IUIWindowSceneDelegate {
[Export ("window")]
public UIWindow? Window { get; set; }

[Export ("scene:willConnectToSession:options:")]
public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
{
if (scene is not UIWindowScene windowScene)
return;

Window = new UIWindow (windowScene);
var vc = new UIViewController ();
var view = vc.View;
Debug.Assert (view is not null, "UIViewController.View should not be null");
view.BackgroundColor = UIColor.SystemBackground;

var label = new UILabel {
Text = "Running tests...\n",
TextAlignment = UITextAlignment.Left,
Lines = 0,
Font = UIFont.GetMonospacedSystemFont (12, UIFontWeight.Regular)!,
Comment thread
jonathanpeppers marked this conversation as resolved.
TextColor = UIColor.Label,
TranslatesAutoresizingMaskIntoConstraints = false,
};
view.AddSubview (label);
var guide = view.SafeAreaLayoutGuide;
label.TopAnchor.ConstraintEqualTo (guide.TopAnchor, 8).Active = true;
label.LeadingAnchor.ConstraintEqualTo (guide.LeadingAnchor, 8).Active = true;
label.TrailingAnchor.ConstraintLessThanOrEqualTo (guide.TrailingAnchor, -8).Active = true;

Window.RootViewController = vc;
Window.MakeKeyAndVisible ();

var consumer = new ResultConsumer ();
consumer.StatusChanged += line =>
vc.InvokeOnMainThread (() => label.Text += line + "\n");

Task.Run (async () => {
try {
var documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
var resultsPath = Path.Combine (documentsPath, "TestResults");

var builder = await TestApplication.CreateBuilderAsync ([
"--results-directory", resultsPath,
"--report-trx"
]);
builder.AddMSTest (() => [typeof (Test1).Assembly]);
builder.AddTrxReportProvider ();
builder.TestHost.AddDataConsumer (_ => consumer);

using ITestApplication app = await builder.BuildAsync ();
await app.RunAsync ();
// UIApplication.Main() keeps the process alive, so exit explicitly
Environment.Exit (consumer.Failed > 0 ? 1 : 0);
} catch (Exception ex) {
Console.WriteLine ($"Error running tests: {ex}");
Environment.Exit (1);
}
});
}

class ResultConsumer : IDataConsumer {
int _passed, _failed, _skipped;
public int Passed => _passed;
public int Failed => _failed;
public int Skipped => _skipped;
public string? TrxReportPath;
public event Action<string>? StatusChanged;

public string Uid => nameof (ResultConsumer);
public string DisplayName => nameof (ResultConsumer);
public string Description => "";
public string Version => "1.0";
public Task<bool> IsEnabledAsync () => Task.FromResult (true);

public Type [] DataTypesConsumed => [typeof (TestNodeUpdateMessage), typeof (SessionFileArtifact)];

public Task ConsumeAsync (IDataProducer dataProducer, IData value, CancellationToken cancellationToken)
{
if (value is SessionFileArtifact artifact) {
TrxReportPath = artifact.FileInfo.FullName;

Console.WriteLine ($"Results: passed={Passed}, failed={Failed}, skipped={Skipped}");
Console.WriteLine ($"TRX report: {TrxReportPath}");
StatusChanged?.Invoke ($"\n✅ {Passed} passed ❌ {Failed} failed ⏭️ {Skipped} skipped");
} else if (value is TestNodeUpdateMessage { TestNode: var node }) {
var state = node.Properties.SingleOrDefault<TestNodeStateProperty> ();
string? outcome = state switch {
PassedTestNodeStateProperty => "passed",
FailedTestNodeStateProperty or ErrorTestNodeStateProperty
or TimeoutTestNodeStateProperty => "failed",
SkippedTestNodeStateProperty => "skipped",
_ => null
};
if (outcome is null)
return Task.CompletedTask;

_ = outcome switch { "passed" => Interlocked.Increment (ref _passed), "failed" => Interlocked.Increment (ref _failed), _ => Interlocked.Increment (ref _skipped) };

var id = node.Properties.SingleOrDefault<TestMethodIdentifierProperty> ();
var testName = id is not null ? $"{id.Namespace}.{id.TypeName}.{id.MethodName}" : node.DisplayName;
Console.WriteLine ($"[{outcome.ToUpperInvariant ()}] {testName}");

var icon = outcome switch { "passed" => "✅", "failed" => "❌", _ => "⏭️" };
StatusChanged?.Invoke ($"{icon} {testName}");
}
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace MacCatalystTest1;

[TestClass]
public sealed class Test1 {
[TestMethod]
public void TestMethod1 ()
{
}

[TestMethod]
public void TestMethod2 ()
{
Assert.Fail ("This test is expected to fail");
}

[TestMethod]
public void TestMethod3 ()
{
Assert.Inconclusive ("This test is expected to be skipped");
Comment thread
jonathanpeppers marked this conversation as resolved.
}
}
Loading
Loading