Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 11, 2025

Please check the following before creating a Pull Request

  • If this is a new feature or piece of functionality, have you started a discussion and gotten agreement on it?
  • If it fixes a bug or problem, is there an issue to track it? If not, create one first and link it please so there's clear visibility.
  • Did you write tests to ensure you code works properly?

Problem

Documentation at docs/docs/test-authoring/depends-on.md instructed users to call TestContext.GetTests() directly, but this method is internal. The public API is TestContext.Dependencies.GetTests().

Changes

Documentation (docs/docs/test-authoring/depends-on.md)

  • Updated method access path from TestContext.GetTests() to TestContext.Dependencies.GetTests()
  • Fixed StateBag usage from StateBag["key"] to StateBag.Items["key"] to match actual API
  • Changed "object bag" terminology to "state bag"

Before:

var addToBagTestContext = TestContext.Current!.GetTests(nameof(AddItemToBag)).First();
var itemId = addToBagTestContext.StateBag["ItemId"];

After:

var addToBagTestContext = TestContext.Current!.Dependencies.GetTests(nameof(AddItemToBag)).First();
var itemId = addToBagTestContext.StateBag.Items["ItemId"];

Verification

Confirmed pattern matches existing test usage in TUnit.TestProject/Bugs/3627/Tests.cs, TUnit.TestProject/DependsOnTests3.cs, and TUnit.TestProject/DependsOnTests2.cs.

Original prompt

This section details on the original issue you should resolve

<issue_title>Sharing data between dependent tests</issue_title>
<issue_description>Hi Tom,

I'm wondering if the documentation for sharing data between dependent tests is actually ahead of the implemented feature. In the documentation here, the following statement is made.

This is done by calling the GetTests method on a TestContext object. It takes the test's method name (so you can use nameof(...)) and optionally the parameter types for if there's multiple overloads.

In the actual code, this GetTests implementation is hidden behind an internal access modifier.

// TestContext.Dependencies.cs

public partial class TestContext
{
    internal List<TestContext> GetTests(string testName)
    {
        // Omitted for brevity
    }

Is there another way a test could "receive an output" from a dependent test in the currently available public API? Thanks!

</issue_description>

<agent_instructions>Fix the docs </agent_instructions>

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

@thomhurst Try TestContext.Dependencies.GetTests(...)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix documentation for sharing data between dependent tests Fix documentation: TestContext.Dependencies.GetTests() is the correct public API Dec 11, 2025
Copilot AI requested a review from thomhurst December 11, 2025 01:59
@thomhurst thomhurst marked this pull request as ready for review December 11, 2025 09:06
Copilot AI review requested due to automatic review settings December 11, 2025 09:06
@thomhurst thomhurst merged commit 2353265 into main Dec 11, 2025
18 of 23 checks passed
@thomhurst thomhurst deleted the copilot/fix-data-sharing-documentation branch December 11, 2025 09:06
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 corrects documentation errors in the "Depends On" feature guide where the documented API paths did not match the actual public API surface. The issue was discovered when users found that TestContext.GetTests() was marked as internal and inaccessible.

Key Changes:

  • Updated API path from TestContext.GetTests() to TestContext.Dependencies.GetTests()
  • Corrected StateBag access from StateBag["key"] to StateBag.Items["key"]
  • Updated terminology from "object bag" to "state bag" for consistency

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

Sharing data between dependent tests

2 participants