dotnet-testing-test-output-logging_skill

This skill guides implementing structured test output and logging in xUnit with ITestOutputHelper, AbstractLogger, and diagnostic tools for .NET tests.
  • C#

19

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill kevintsengtw/dotnet-testing-agent-skills --skill dotnet-testing-test-output-logging

  • SKILL.md10.1 KB

Overview

This skill is a practical guide for implementing robust test output and logging in .NET xUnit projects. It explains how to use ITestOutputHelper correctly, create test-friendly ILogger implementations (XUnitLogger, AbstractLogger, CompositeLogger), and design structured, diagnostic output for unit and performance tests.

How this skill works

It inspects common xUnit patterns and provides concrete implementations and patterns you can adopt: constructor injection of ITestOutputHelper, an AbstractLogger base to simplify mocking, an XUnitLogger that writes log entries to test output, and a CompositeLogger to combine mock verification with visible output. It also shows how to record timestamps and checkpoints for performance diagnostics.

When to use it

  • When you need deterministic test diagnostics visible in xUnit output
  • When testing code that depends on ILogger and you need a verifiable substitute
  • When you want structured, consistent logs to debug failing tests
  • When running performance or long-running tests that need time-point reporting
  • When combining assertionable behavior with human-readable test logs

Best practices

  • Inject ITestOutputHelper via constructor; do not store it in static fields
  • Use structured sections, key-value lines, and timestamps for readable output
  • Prefer AbstractLogger to simplify mocking Log<TState> behavior in tests
  • Verify log level and relevant message fragments rather than exact text
  • Combine a mock logger with XUnitLogger via CompositeLogger for both verification and visible output
  • Avoid logging sensitive data and excessive output that slows tests

Example use cases

  • Unit test that asserts error handling and verifies an Error-level log was produced
  • Integration test where XUnitLogger writes progress and failures to test output for debugging
  • Performance test that records checkpoints and prints elapsed milliseconds per stage
  • Service test using CompositeLogger to both assert log interactions and dump readable messages
  • Diagnostic test base class that standardizes LogTestStart, LogTestData, and assertion failure output

FAQ

xUnit provides a fresh ITestOutputHelper per test instance. Constructor injection ensures correct lifecycle, avoids static sharing, and prevents cross-test contamination.

How do I assert ILogger calls since extension methods are hard to mock?

Intercept the underlying Log<TState> call or create an AbstractLogger<T> base you can substitute; verify log level and message fragments rather than exact formatted strings.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational