Skip to content

Support MSTest v4 - #157

Open
jeremy-visionaid wants to merge 10 commits into
mattleibow:mainfrom
jeremy-visionaid:mstest4
Open

jeremy-visionaid wants to merge 10 commits into
mattleibow:mainfrom
jeremy-visionaid:mstest4

Conversation

@jeremy-visionaid

@jeremy-visionaid jeremy-visionaid commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: #147

@jeremy-visionaid

jeremy-visionaid commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@Evangelink This is an attempt to work around microsoft/testfx#9809 in MSTest v4 using server mode in-process. It works OK for the situations that I need it to, but it's also mostly agent stuff. I was hoping you might be a better judge than me as to whether this looks roughly sane!

@jeremy-visionaid
jeremy-visionaid marked this pull request as ready for review July 22, 2026 02:52
@jeremy-visionaid
jeremy-visionaid marked this pull request as draft July 22, 2026 03:45
@mattleibow
mattleibow requested a review from Copilot July 23, 2026 09:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Visual Runner backend to support MSTest v4 (Microsoft Testing Platform) by hosting MSTest in-process via MTP “server mode” JSON-RPC, and wires it into the sample device test app with a new MSTest sample test project.

Changes:

  • Introduces DeviceRunners.VisualRunners.MSTest with server-mode JSON-RPC hosting, discovery, and execution plumbing.
  • Adds MSTest sample tests and integrates MSTest into the sample DeviceTestingKitApp.DeviceTests runner configuration.
  • Adds central package versions for Microsoft Testing Platform and MSTest v4 packages.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/DeviceRunners.VisualRunners.MSTest/WireTestNode.cs Parses server-mode node updates into a typed representation (state, location, traits).
src/DeviceRunners.VisualRunners.MSTest/VisualTestRunnerConfigurationBuilderExtensions.cs Adds .AddMSTest() builder extension to register MSTest discoverer/runner.
src/DeviceRunners.VisualRunners.MSTest/MSTestTestRunner.cs Executes selected MSTest tests by UID and reports results back to the runner channels.
src/DeviceRunners.VisualRunners.MSTest/MSTestTestResultInfo.cs Maps terminal node states into ITestResultInfo results (pass/skip/fail).
src/DeviceRunners.VisualRunners.MSTest/MSTestTestDiscoverer.cs Discovers MSTest tests by running an MTP discovery session and collecting discovered action nodes.
src/DeviceRunners.VisualRunners.MSTest/MSTestTestCaseInfo.cs Represents an MSTest test case and derives class/method names from node location fields.
src/DeviceRunners.VisualRunners.MSTest/MSTestTestAssemblyInfo.cs Represents a test assembly and retains the runtime Assembly for platforms without Assembly.Location.
src/DeviceRunners.VisualRunners.MSTest/MSTestTestAssemblyConfiguration.cs Provides an MSTest assembly configuration placeholder.
src/DeviceRunners.VisualRunners.MSTest/MSTestServerModeHost.cs Implements the server-mode JSON-RPC framing/handshake and streams node update notifications.
src/DeviceRunners.VisualRunners.MSTest/DeviceRunners.VisualRunners.MSTest.csproj Adds new MSTest visual runner library project and MTP/MSTest adapter dependencies.
sample/test/DeviceTestingKitApp.Library.MSTestTests/ViewModels/CounterViewModelTests.cs Adds sample MSTest tests for the library view model.
sample/test/DeviceTestingKitApp.Library.MSTestTests/Usings.cs Adds global MSTest using for the sample MSTest test project.
sample/test/DeviceTestingKitApp.Library.MSTestTests/UnitTests.cs Adds broader MSTest sample tests (skip, failure, data-driven, cancellation token usage).
sample/test/DeviceTestingKitApp.Library.MSTestTests/DeviceTestingKitApp.Library.MSTestTests.csproj Adds MSTest v4 sample test project (test attributes only; runner hosted by DeviceRunners).
sample/test/DeviceTestingKitApp.DeviceTests/MauiProgram.cs Registers MSTest test assembly and enables MSTest runner in the sample app.
sample/test/DeviceTestingKitApp.DeviceTests/DeviceTestingKitApp.DeviceTests.csproj References the MSTest sample test project and the MSTest visual runner project.
Directory.Packages.props Adds central versions for Microsoft.Testing.Platform and MSTest v4 packages.
DeviceRunners.slnx Adds the new MSTest runner project and sample MSTest test project to the solution.
Comments suppressed due to low confidence (1)

src/DeviceRunners.VisualRunners.MSTest/MSTestServerModeHost.cs:155

  • DriveSessionAsync only sends the JSON-RPC "exit" request after the operation completes normally. If ReadUntilResponseAsync throws (for example due to cancellation or a framing/parse error), the exit request is skipped, which can leave the in-process server host running and cause RunSessionAsync to hang while awaiting serverTask.
		// 3. stream node updates until the request completes.
		await ReadUntilResponseAsync(stream, OperationRequestId, onNode, cancellationToken);

		// 4. ask the server to exit.
		await SendAsync(stream, new { jsonrpc = "2.0", method = "exit" }, cancellationToken);
	}

Comment thread src/DeviceRunners.VisualRunners.MSTest/MSTestServerModeHost.cs Outdated
Comment thread src/DeviceRunners.VisualRunners.MSTest/DeviceRunners.VisualRunners.MSTest.csproj Outdated
(2, "second")
];

public TestContext TestContext { get; set; }
@Evangelink

Copy link
Copy Markdown

Hey @jeremy-visionaid,

I'll have a look at this next week - sorry for the delay!

@jeremy-visionaid

Copy link
Copy Markdown
Contributor Author

Thanks! I also haven't had a chance yet to see how this fits in with the work that other people have been doing (e.g. #130) and the efforts you mentioned from @jonathanpeppers. I'm already consuming this internally from a private feed and it's working OK for me. But maybe this might be useful to other people, even as an interim/throwaway thing

@jonathanpeppers

Copy link
Copy Markdown

This repo basically replaces the VSTest target with its own thing that writes the test result .xml files.

This is the approach I'd take if I didn't want to make changes in dotnet/sdk, and is a good way to retroactively add this to .NET 10.

For .NET 11 we really only implemented MTP, because it was the new thing.

@Evangelink

Copy link
Copy Markdown

Sorry @jeremy-visionaid! With vacations and some other activities, I totally forgot to have a look at this. Adding a note for Monday!

@Evangelink

Copy link
Copy Markdown

Thanks for putting this together — after reviewing the approach, I think MTP server mode is reasonable for the visual-runner scenario. It is currently the supported way to receive discovery updates without executing tests.

Rather than maintaining the hand-written JSON-RPC/framing implementation, I suggest trying the new Microsoft.Testing.Platform.ServerMode.Client.Sources package. It provides the canonical typed client for initialization, discovery, selected execution, cancellation, errors, output, attachments, and shutdown, using protocol sources maintained alongside the server.

You can already consume our latest builds from the public test-tools feed by following the MSTest early-access instructions. This would let you start adapting the PR now and give us feedback before MTP 2.4 ships. We currently plan to release 2.4 this week, unless a blocker arises.

The client's existing LaunchAsync(path) starts a child process, so it does not directly fit this in-process MAUI host. I opened microsoft/testfx#10890 to add a callback-based in-process launch API. The intended shape lets DeviceRunners continue creating the TestApplication and registering MSTest in the app process, while the client owns the listener, protocol setup, timeout, cancellation, and teardown.

I would recommend reworking this PR around the source client and trying the preview packages now. Ideally, DeviceRunners would then only need to launch MTP in-process and map typed test-node updates into its visual-runner abstractions, removing most of MSTestServerModeHost and WireTestNode.

Feedback from this integration would be especially useful for validating the in-process launch API before it is finalized.

@jeremy-visionaid

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback guys!

@Evangelink Yup, the hand-rolled JSON and LaunchAsync parts were the bits I was really bothered by but couldn't find better ways of doing them. Glad to hear I'm not going mad... Thanks opening the ticket and for pointing me in the right direction there!

Thanks also @jonathanpeppers for your review and fixing the related Android concurrent build issue too. Much appreciated!

@Evangelink

Copy link
Copy Markdown

Thanks for your patience and for opening a fruitful ticket and not simply giving up or having useless rant!

@jeremy-visionaid

Copy link
Copy Markdown
Contributor Author

@Evangelink I saw Microsoft.Testing.Platform.ServerMode.Client.Sources just got released on NuGet. This looks much cleaner now, drops about 200 lines, thanks for the review!

@Evangelink Evangelink left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two result-fidelity issues to address before merging.

Comment thread src/DeviceRunners.VisualRunners.MSTest/MSTestTestRunner.cs
Comment thread src/DeviceRunners.VisualRunners.MSTest/MSTestTestResultInfo.cs Outdated
@jeremy-visionaid
jeremy-visionaid marked this pull request as ready for review September 7, 2026 00:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support MSTest, Microsoft Testing Framework

4 participants