Labcoat.Testing.MSTest
1.2.1
See the version list below for details.
dotnet add package Labcoat.Testing.MSTest --version 1.2.1
NuGet\Install-Package Labcoat.Testing.MSTest -Version 1.2.1
<PackageReference Include="Labcoat.Testing.MSTest" Version="1.2.1" />
<PackageVersion Include="Labcoat.Testing.MSTest" Version="1.2.1" />
<PackageReference Include="Labcoat.Testing.MSTest" />
paket add Labcoat.Testing.MSTest --version 1.2.1
#r "nuget: Labcoat.Testing.MSTest, 1.2.1"
#:package Labcoat.Testing.MSTest@1.2.1
#addin nuget:?package=Labcoat.Testing.MSTest&version=1.2.1
#tool nuget:?package=Labcoat.Testing.MSTest&version=1.2.1
Labcoat.Testing.MSTest
MSTest helpers for Labcoat: give each MSTest integration test its own
OpenTelemetry trace, so Labcoat can show a View trace / Structured logs link that jumps straight to what the
services did during that test in the Aspire dashboard, and stream console output live while a test runs. Built on
Labcoat.Testing (the framework-neutral core, brought in by this
package). AOT-compatible: works in trimmed and Native AOT test apps (see the note under
Trace only some tests).
Setup: two steps
Add the package and the two hooks (or derive the test classes from
LabcoatTracedTestinstead of the hooks):dotnet add MyApp.Tests package Labcoat.Testing.MSTestusing Labcoat.Testing; [TestClass] public static class LabcoatHooks { [GlobalTestInitialize] public static void Start(TestContext c) => LabcoatMSTest.StartTest(c); [GlobalTestCleanup] public static void End(TestContext c) => LabcoatMSTest.EndTest(c); }Call
LabcoatTracing.ConfigureAspireTesting(builder)in the fixture that creates the app (an[AssemblyInitialize]method, or the shared class the tests start the app from), afterCreateAsyncand beforeBuildAsync. Without it the services the tests start send their telemetry to the testing default (localhost:4317, usually nothing), and the dashboard shows the test's span but none of the services' spans or logs.var builder = await DistributedApplicationTestingBuilder.CreateAsync<Projects.MyAppHost>(ct); LabcoatTracing.ConfigureAspireTesting(builder); var app = await builder.BuildAsync(ct);A complete fixture: AspireSample.Tests/Integration/AspireAppFixture.cs.
Tracing is a no-op unless the tests run under Labcoat hosted by an Aspire AppHost (builder.AddLabcoat(...)) with
trace collection turned on. It is opt-in and off by default: enable it with .WithTestTracing() on the Labcoat
resource, the Toggle test tracing dashboard command or the toggle in the Labcoat UI. Safe to leave in place for
dotnet test and CI.
StartTest starts an Activity named after the test (exported to the dashboard under the test assembly's name, tagged
with the test's class, method and display name) and writes labcoat:traceId=<hex> to the test output; Labcoat strips
that line and links the test to /traces/detail/<traceId>. HTTP calls made during the test carry the W3C
traceparent header, so the service spans join the test's trace. EndTest tags the outcome (test.outcome; failed,
error, timeout and aborted tests get an error status).
Trace only some tests
A trace filter in the Labcoat UI's search syntax (cat:Integration, trait:Kind=Slow, name text) limits tracing to
the matching tests. From the AppHost: .WithTestTracing(filter: "cat:Integration") (it wins). As the test project's
default:
[assembly: LabcoatTracing(Filter = "cat:Integration")] // or on a test class; or <LabcoatTracingFilter> in the .csproj
The adapter reads the test's [TestCategory] (method, class, base classes, assembly), [TestProperty], [Owner],
[Priority] and [Description], the traits MSTest reports to Labcoat, so cat:Integration matches
[TestCategory("Integration")] and trait:Kind=Slow matches [TestProperty("Kind", "Slow")]. A test that doesn't
match gets no span and no trace id. The hooks still do the tracing; the attribute only narrows it. See
Trace only some tests.
MSTest's TestContext doesn't expose these attributes, so the adapter reads them from the test class by reflection.
In a trimmed or Native AOT test app whose test class (or method) metadata was removed, the test has no categories or
traits: a cat: / trait: filter then doesn't match it (no span), and nothing throws.
Live console output
MSTest attaches console output to a test's result only when the test ends. LabcoatOutput makes lines appear in
Labcoat's detail pane while the test is still running, and in the test's normal output afterwards:
LabcoatOutput.WriteLine(TestContext, "Starting the Aspire app…");
using var log = LabcoatOutput.CreateWriter(TestContext); // a TextWriter (one live line per completed line)
Under Labcoat (LABCOAT_TEST_HOST=1) each line is also written to the process's raw stdout as a labcoat:live: marker
tagged with the test's class, method and display name, so Labcoat attributes it exactly, also for data rows and parallel
tests. Outside Labcoat it is just Console.WriteLine. No tracing setup is needed for this.
Migrating from Labcoat.Testing 0.1 (MSTest)
The MSTest parts of Labcoat.Testing moved to this package; Labcoat.Testing is now framework neutral.
- Replace the package:
Labcoat.Testing→Labcoat.Testing.MSTest(it bringsLabcoat.Testingalong). - In your hooks,
LabcoatTracing.StartTest(c)/LabcoatTracing.EndTest(c)becomeLabcoatMSTest.StartTest(c)/LabcoatMSTest.EndTest(c).
Unchanged: the namespace (using Labcoat.Testing;), LabcoatTracing.ConfigureAspireTesting, LabcoatTracing.IsEnabled
and its constants, the LabcoatTracedTest base class and LabcoatOutput. The spans now also carry
test.framework = mstest.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Labcoat.Testing (>= 1.2.1)
- MSTest.TestFramework (>= 4.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.