Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 13, 2025

Description

TUnit already supports test artifacts via TestContext.Output.AttachArtifact() and TestSessionContext.AddArtifact(), but lacked documentation. Users migrating from NUnit were confused by the missing equivalent to TestContext.AddTestAttachment().

Added:

  • Comprehensive artifacts guide (docs/docs/test-lifecycle/artifacts.md)

    • Test-level and session-level artifact APIs
    • Best practices: cleanup, organization, conditional attachment
    • Real-world examples: Playwright screenshots, API logs, database queries
    • CI/CD integration notes
  • Updated test-context.md

    • Added "Test Output and Artifacts" section
    • Documented both Output.WriteLine() (interface-based) and OutputWriter.WriteLine() (direct TextWriter) patterns
  • Updated migration guides (NUnit, MSTest, xUnit)

    • Mapped framework-specific attachment APIs to TUnit's Artifact class

Example usage:

// Test-level artifact
TestContext.Current!.Output.AttachArtifact(new Artifact
{
    File = new FileInfo("screenshot.png"),
    DisplayName = "Failure Screenshot",
    Description = "Screenshot captured when test failed"
});

// Session-level artifact
TestSessionContext.Current!.AddArtifact(new Artifact
{
    File = new FileInfo("test-session-log.txt"),
    DisplayName = "Test Session Log"
});

Related Issue

Fixes #4612

Type of Change

  • Documentation update

Checklist

Required

  • I have read the Contributing Guidelines
  • If this is a new feature, I started a discussion first and received agreement
  • My code follows the project's code style (modern C# syntax, proper naming conventions)
  • I have written tests that prove my fix is effective or my feature works

TUnit-Specific Requirements

  • Dual-Mode Implementation: N/A - documentation only
  • Snapshot Tests: N/A - no code changes
  • Performance: N/A - documentation only
  • AOT Compatibility: N/A - documentation only

Testing

  • All existing tests pass (dotnet test)
  • I have added tests that cover my changes (N/A - existing TestArtifactTests.cs validates documented API)
  • I have tested both source-generated and reflection modes (if applicable)

Additional Notes

Documentation builds successfully with Docusaurus. All internal links resolve correctly. Existing artifact test validates the documented API works as specified.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: Add support for test attachments</issue_title>
<issue_description>### Problem Statement

We recently started migration of our whole test suite from NUnit to TUnit. We quickly realized there might be a blocker for us: we make extensive use of test attachments, particularly in integration tests. For us they are indispensable for figuring out why integration tests fail.

In NUnit we do TestContext.AddTestAttachment(filePath, name) but I cannot find anything in the TUnit TestContext that looks like an equivalent, nor can I find any mention of attachments or artifacts in the docs.

As far as I can tell it was added to MTP 1.7 back in March.

Is this already possible in TUnit and I've just not looked in the right place? If not, any chance we could get this added to TUnit?

Proposed Solution

I would like TUnit to support test attachments through a mechanism similar to that of NUnit.

Alternatives Considered

No response

Feature Category

Test Output / Reporting

How important is this feature to you?

Critical - blocking my adoption/usage of TUnit

Additional Context

No response

Contribution

  • I'm willing to submit a pull request for this feature</issue_description>

<agent_instructions>Can you add documentation for attaching artifacts. We should add documentation for artifacts on both the test level, and the entire test session level</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@thomhurst Heya @DaRosenberg - Is `TestContext.Current.Output.AttachArtifact(...)` what you're looking for?

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add support for test attachments in TUnit Add documentation for test artifacts/attachments Dec 14, 2025
Copilot AI requested a review from thomhurst December 14, 2025 00:09
@thomhurst thomhurst marked this pull request as ready for review December 14, 2025 04:35
Copilot AI review requested due to automatic review settings December 14, 2025 04:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive documentation for TUnit's existing test artifact/attachment functionality, addressing user confusion about how to migrate from NUnit's TestContext.AddTestAttachment() API.

Key changes:

  • New comprehensive artifacts guide covering test-level and session-level artifacts with real-world examples
  • Updated test-context.md to document the Output.AttachArtifact() API
  • Migration guide updates for NUnit, MSTest, and xUnit showing equivalent artifact attachment patterns

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
docs/docs/test-lifecycle/artifacts.md New comprehensive guide documenting artifact attachment at test and session levels, with best practices and common use cases (Playwright, API testing, database testing)
docs/docs/test-lifecycle/test-context.md Added "Test Output and Artifacts" section explaining both Output.WriteLine() and OutputWriter.WriteLine() patterns, plus artifact attachment
docs/sidebars.ts Added artifacts.md to the test-lifecycle section navigation
docs/docs/migration/nunit.md Added test attachment migration example showing NUnit's TestContext.AddTestAttachment() mapped to TUnit's Artifact class
docs/docs/migration/mstest.md Added test attachment migration example showing MSTest's TestContext.AddResultFile() mapped to TUnit's Artifact class
docs/docs/migration/xunit.md Added test attachment migration example showing xUnit v3's FileAttachment mapped to TUnit's Artifact class
docs/yarn.lock Dependency version updates (unrelated to the documentation feature)

This was referenced Dec 18, 2025
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.

[Feature]: Add support for test attachments

2 participants