Skip to main content
The Test SDK (ANcpLua.NET.Sdk.Test) provides xUnit v3 with Microsoft Testing Platform and injects base classes for integration testing.

Microsoft Testing Platform (MTP)

The SDK uses xUnit v3 with Microsoft Testing Platform instead of VSTest.

Auto-Configuration

MTP requires test projects to output executables. The SDK handles this automatically when you reference xunit.v3.mtp-v2:

CLI Syntax

MTP uses different command syntax than VSTest:
VSTest syntax causes exit code 5 with MTP. Use --filter-method instead of --filter "FQN~" and --report-trx instead of --logger trx.
.NET 10 includes native MTP support via global.json. The -- separator is only needed for .NET 8/9 with explicit MTP opt-in.

Troubleshooting

xUnit v3 TestContext

xUnit v3 replaces constructor-injected ITestOutputHelper with ambient TestContext. Access test output anywhere without passing it through constructor chains.

Before vs After

Migration Example

TestContext.Current is available anywhere during test execution - in test methods, helper classes, or builder patterns - without explicit parameter passing.

IntegrationTestBase

In-memory TestServer for fast API testing.
Uses WebApplicationFactory<TProgram> internally.

KestrelTestBase

Real Kestrel server for HTTP/2, WebSockets, SSE, or Playwright.
Starts on random port via UseKestrel(0).

FakeLogger

See Extensions for FakeLogCollector test helpers.

AOT/Trim Testing

The SDK provides infrastructure for testing Native AOT and trimmed applications. Tests run as separate processes with PublishAot=true or PublishTrimmed=true to verify runtime behavior.

Enabling AOT Testing

This automatically references ANcpLua.AotTesting.Attributes.

Writing AOT Tests

AOT tests are methods returning int with exit code 100 for success:

Test Attributes

Publishes with PublishAot=true and executes the native binary.
Publishes with PublishTrimmed=true for testing IL trimming.
In-process markers verified by analyzers (AL0043, AL0044):
Marks code that intentionally uses AOT-incompatible patterns. AL0052 prevents [AotSafe] code from calling [AotUnsafe] code, and AL0053 flags unnecessary [AotUnsafe] attributes.

TrimAssert Helpers

Verify types are trimmed or preserved at runtime:
Do not use typeof(X) in assertions—it roots the type and prevents trimming. Use string-based TrimAssert methods instead.

Feature Switches

Disable runtime features during tests:

How It Works

  1. Discovery: MSBuild target scans for [AotTest]/[TrimTest] methods
  2. Project Generation: Creates temporary .csproj for each test
  3. Publish: Runs dotnet publish with AOT/Trim flags
  4. Execute: Runs the published executable
  5. Validate: Checks exit code (100 = success)

Exit Code Convention