Skip to content

Add test for dotnet test with UseAppHost=false in MTP #50109

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

Merged
merged 13 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Microsoft.Testing.Platform.Builder;
using Microsoft.Testing.Platform.Capabilities.TestFramework;
using Microsoft.Testing.Platform.Extensions.Messages;
using Microsoft.Testing.Platform.Extensions.TestFramework;

var testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);

testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, __) => new DummyTestAdapter());

using var testApplication = await testApplicationBuilder.BuildAsync();
return await testApplication.RunAsync();

public class DummyTestAdapter : ITestFramework, IDataProducer
{
public string Uid => nameof(DummyTestAdapter);

public string Version => "2.0.0";

public string DisplayName => nameof(DummyTestAdapter);

public string Description => nameof(DummyTestAdapter);

public Task<bool> IsEnabledAsync() => Task.FromResult(true);

public Type[] DataTypesProduced => [];

public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context)
=> Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });

public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context)
=> Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });

public Task ExecuteRequestAsync(ExecuteRequestContext context)
{
// Simple dummy test that always passes
context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(
context.Request.Session.SessionUid,
new TestNode()
{
Uid = "dummy_test_1",
DisplayName = "Dummy Test 1",
Properties = new PropertyBag()
}));

context.MessageBus.PublishAsync(this, new TestResultMessage(
context.Request.Session.SessionUid,
new PassedTestResult()
{
Uid = "dummy_test_1",
DisplayName = "Dummy Test 1",
Duration = TimeSpan.FromMilliseconds(1)
}));

context.Complete();
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />

<PropertyGroup>
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<UseAppHost>false</UseAppHost>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Testing.Platform" Version="$(MicrosoftTestingPlatformVersion)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[general]
telemetry-output=false

[testing.platform]
use-microsoft-testing-platform=true
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Xml.Linq;
using Microsoft.DotNet.Cli.Commands;
using Microsoft.DotNet.Cli.Commands.Test;
using CommandResult = Microsoft.DotNet.Cli.Utils.CommandResult;
Expand Down Expand Up @@ -374,5 +375,26 @@ public void RunningWithGlobalPropertyShouldProperlyPropagate(string configuratio

result.ExitCode.Should().Be(ExitCodes.Success);
}

[Fact]
public void RunMTPProjectWithUseAppHostFalseAndArchMismatch_ShouldFailWithProperError()
{
TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectMTPWithUseAppHostFalse", Guid.NewGuid().ToString())
.WithSource();

// Call test with wrong architecture
CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
.WithWorkingDirectory(testInstance.Path)
.Execute("--arch", "wrongArchitecture");

// Verify proper error is shown for architecture mismatch
if (!TestContext.IsLocalized())
{
// Should provide clear error about architecture mismatch when UseAppHost=false
result.StdOut.Should().Contain("architecture");
}

result.ExitCode.Should().Be(ExitCodes.GenericFailure);
}
}
}
Loading