Expose results directory through TestContext - #6575
Conversation
|
Warning Review limit reached
Next review available in: 4 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
Comment |
Greptile SummaryExposes Microsoft.Testing.Platform's resolved results directory through the public
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The public property is initialized from the same platform results-directory source used by existing reporters, and runtime coverage verifies its resolution, existence, and configuration consistency.
|
| Filename | Overview |
|---|---|
| src/TUnit.Core/TestContext.cs | Adds a guarded public static property exposing the initialized results-directory path. |
| src/TUnit.Engine/Framework/TUnitServiceProvider.cs | Initializes the new property from Microsoft.Testing.Platform's resolved configuration during provider construction. |
| tests/TUnit.TestProject/TestContextTests.cs | Verifies the exposed directory is fully qualified, exists, and matches the platform configuration. |
| docs/docs/writing-tests/artifacts.md | Documents writing and attaching generated files in the results directory. |
Reviews (1): Last reviewed commit: "feat: expose results directory" | Re-trigger Greptile
There was a problem hiding this comment.
Code Review
Reviewed the new TestContext.ResultsDirectory API and its documentation.
Implementation (TestContext.cs, TUnitServiceProvider.cs) looks solid: lazily throws a clear InvalidOperationException if accessed before engine init, sourced correctly from Microsoft.Testing.Platform's GetTestResultDirectory(), public API surface updated consistently across all target frameworks (net8/9/10, net4.7), and covered by a new engine test (ResultsDirectory_Is_Exposed) that asserts it's a fully-qualified, existing directory matching the platform config.
Issue: doc example writes to a fixed shared filename (collision risk under parallel execution)
docs/docs/writing-tests/artifacts.md (new CaptureLog example):
var artifactPath = Path.Combine(TestContext.ResultsDirectory, "application.log");
await File.WriteAllTextAsync(artifactPath, "Diagnostic information");ResultsDirectory is one process-wide directory, not per-test. TUnit runs tests in parallel by default, so if this pattern is copied by multiple tests (or a data-driven test with multiple cases), each writes to the exact same application.log path concurrently — causing sharing-violation IOExceptions or silently overwritten/lost diagnostic output.
The companion doc this PR also touches (test-context.md) already documents TestContext.Current!.Isolation a few lines below for producing unique per-test resource names — the new example should use that (or another unique-naming scheme, e.g. TestContext.Current!.TestDetails.TestId) to avoid teaching a pattern that breaks under the framework's own default parallelism.
Suggested fix:
var artifactPath = Path.Combine(TestContext.ResultsDirectory, $"application-{TestContext.Current!.Isolation}.log");Everything else in the PR (implementation, API surface, tests) looks correct and ready to merge once the doc example is fixed.
Updated [TUnit](https://github.com/thomhurst/TUnit) from 1.63.0 to 1.64.6. <details> <summary>Release notes</summary> _Sourced from [TUnit's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.64.6 <!-- Release notes generated using configuration in .github/release.yml at v1.64.6 --> ## What's Changed ### Other Changes * Switch NuGet publishing to trusted publishing by @thomhurst in thomhurst/TUnit#6573 * Expose results directory through TestContext by @thomhurst in thomhurst/TUnit#6575 * Fix outcome timeline overflow in HTML reports by @thomhurst in thomhurst/TUnit#6574 ### Dependencies * chore(deps): update tunit to 1.64.0 by @thomhurst in thomhurst/TUnit#6570 **Full Changelog**: thomhurst/TUnit@v1.64.0...v1.64.6 ## 1.64.0 <!-- Release notes generated using configuration in .github/release.yml at v1.64.0 --> ## What's Changed ### Other Changes * Honor cancellation tokens linked by custom test executors by @thomhurst in thomhurst/TUnit#6565 * Fix linked cancellation from before-test hooks by @thomhurst in thomhurst/TUnit#6568 * Add per-test execution cancellation by @thomhurst in thomhurst/TUnit#6569 ### Dependencies * chore(deps): update tunit to 1.63.25 by @thomhurst in thomhurst/TUnit#6559 * chore(deps): update dependency serialize-javascript to v7.1.0 by @thomhurst in thomhurst/TUnit#6561 * chore(deps): update dependency nsubstitute to 6.1.0 by @thomhurst in thomhurst/TUnit#6564 * chore(deps): bump mermaid from 11.15.0 to 11.16.1 in /docs by @dependabot[bot] in thomhurst/TUnit#6563 * chore(deps): bump nanoid from 3.3.16 to 3.3.18 in /docs by @dependabot[bot] in thomhurst/TUnit#6562 **Full Changelog**: thomhurst/TUnit@v1.63.25...v1.64.0 ## 1.63.25 <!-- Release notes generated using configuration in .github/release.yml at v1.63.25 --> ## What's Changed ### Other Changes * Fix Mermaid label contrast in dark mode by @thomhurst in thomhurst/TUnit#6531 * Enhance matrix tests documentation by @koryphaee in thomhurst/TUnit#6537 * fix: support nested Member after IsTypeOf by @mvanhorn in thomhurst/TUnit#6540 * docs: Add documentation for TestContext.Parameters by @thomhurst with @Copilot in thomhurst/TUnit#6558 * fix: run event receivers on injected properties by @thomhurst in thomhurst/TUnit#6556 ### Dependencies * chore(deps): update tunit to 1.63.0 by @thomhurst in thomhurst/TUnit#6526 * chore(deps): update dependency stackexchange.redis to 3.1.0 by @thomhurst in thomhurst/TUnit#6529 * chore(deps): update verify to 31.28.0 by @thomhurst in thomhurst/TUnit#6532 * chore(deps): update dependency stackexchange.redis to 3.1.3 by @thomhurst in thomhurst/TUnit#6541 * chore(deps): update dependency dompurify to v3.4.13 by @thomhurst in thomhurst/TUnit#6542 * chore(deps): update dependency rabbitmq.client to 7.2.2 by @thomhurst in thomhurst/TUnit#6546 * chore(deps): update dependency polyfill to 11.0.2 by @thomhurst in thomhurst/TUnit#6549 * chore(deps): update dependency polyfill to 11.0.2 by @thomhurst in thomhurst/TUnit#6548 * chore(deps): bump fast-uri from 3.1.4 to 3.1.5 in /docs by @dependabot[bot] in thomhurst/TUnit#6545 * chore(deps): bump postcss from 8.5.22 to 8.5.25 in /docs by @dependabot[bot] in thomhurst/TUnit#6547 * chore(deps): update dependency stackexchange.redis to 3.1.11 by @thomhurst in thomhurst/TUnit#6550 * chore(deps): update dependency stackexchange.redis to 3.1.13 by @thomhurst in thomhurst/TUnit#6552 ## New Contributors * @koryphaee made their first contribution in thomhurst/TUnit#6537 **Full Changelog**: thomhurst/TUnit@v1.63.0...v1.63.25 Commits viewable in [compare view](thomhurst/TUnit@v1.63.0...v1.64.6). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Updated [TUnit.Core](https://github.com/thomhurst/TUnit) from 1.63.0 to 1.64.6. <details> <summary>Release notes</summary> _Sourced from [TUnit.Core's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.64.6 <!-- Release notes generated using configuration in .github/release.yml at v1.64.6 --> ## What's Changed ### Other Changes * Switch NuGet publishing to trusted publishing by @thomhurst in thomhurst/TUnit#6573 * Expose results directory through TestContext by @thomhurst in thomhurst/TUnit#6575 * Fix outcome timeline overflow in HTML reports by @thomhurst in thomhurst/TUnit#6574 ### Dependencies * chore(deps): update tunit to 1.64.0 by @thomhurst in thomhurst/TUnit#6570 **Full Changelog**: thomhurst/TUnit@v1.64.0...v1.64.6 ## 1.64.0 <!-- Release notes generated using configuration in .github/release.yml at v1.64.0 --> ## What's Changed ### Other Changes * Honor cancellation tokens linked by custom test executors by @thomhurst in thomhurst/TUnit#6565 * Fix linked cancellation from before-test hooks by @thomhurst in thomhurst/TUnit#6568 * Add per-test execution cancellation by @thomhurst in thomhurst/TUnit#6569 ### Dependencies * chore(deps): update tunit to 1.63.25 by @thomhurst in thomhurst/TUnit#6559 * chore(deps): update dependency serialize-javascript to v7.1.0 by @thomhurst in thomhurst/TUnit#6561 * chore(deps): update dependency nsubstitute to 6.1.0 by @thomhurst in thomhurst/TUnit#6564 * chore(deps): bump mermaid from 11.15.0 to 11.16.1 in /docs by @dependabot[bot] in thomhurst/TUnit#6563 * chore(deps): bump nanoid from 3.3.16 to 3.3.18 in /docs by @dependabot[bot] in thomhurst/TUnit#6562 **Full Changelog**: thomhurst/TUnit@v1.63.25...v1.64.0 ## 1.63.25 <!-- Release notes generated using configuration in .github/release.yml at v1.63.25 --> ## What's Changed ### Other Changes * Fix Mermaid label contrast in dark mode by @thomhurst in thomhurst/TUnit#6531 * Enhance matrix tests documentation by @koryphaee in thomhurst/TUnit#6537 * fix: support nested Member after IsTypeOf by @mvanhorn in thomhurst/TUnit#6540 * docs: Add documentation for TestContext.Parameters by @thomhurst with @Copilot in thomhurst/TUnit#6558 * fix: run event receivers on injected properties by @thomhurst in thomhurst/TUnit#6556 ### Dependencies * chore(deps): update tunit to 1.63.0 by @thomhurst in thomhurst/TUnit#6526 * chore(deps): update dependency stackexchange.redis to 3.1.0 by @thomhurst in thomhurst/TUnit#6529 * chore(deps): update verify to 31.28.0 by @thomhurst in thomhurst/TUnit#6532 * chore(deps): update dependency stackexchange.redis to 3.1.3 by @thomhurst in thomhurst/TUnit#6541 * chore(deps): update dependency dompurify to v3.4.13 by @thomhurst in thomhurst/TUnit#6542 * chore(deps): update dependency rabbitmq.client to 7.2.2 by @thomhurst in thomhurst/TUnit#6546 * chore(deps): update dependency polyfill to 11.0.2 by @thomhurst in thomhurst/TUnit#6549 * chore(deps): update dependency polyfill to 11.0.2 by @thomhurst in thomhurst/TUnit#6548 * chore(deps): bump fast-uri from 3.1.4 to 3.1.5 in /docs by @dependabot[bot] in thomhurst/TUnit#6545 * chore(deps): bump postcss from 8.5.22 to 8.5.25 in /docs by @dependabot[bot] in thomhurst/TUnit#6547 * chore(deps): update dependency stackexchange.redis to 3.1.11 by @thomhurst in thomhurst/TUnit#6550 * chore(deps): update dependency stackexchange.redis to 3.1.13 by @thomhurst in thomhurst/TUnit#6552 ## New Contributors * @koryphaee made their first contribution in thomhurst/TUnit#6537 **Full Changelog**: thomhurst/TUnit@v1.63.0...v1.63.25 Commits viewable in [compare view](thomhurst/TUnit@v1.63.0...v1.64.6). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Summary
TestContext.ResultsDirectoryIConfiguration.GetTestResultDirectory(), preserving--results-directoryand configuration overridesTesting
dotnet test tests/TUnit.TestProject/TUnit.TestProject.csproj --framework net10.0 --no-restore --treenode-filter "/*/*/TestContextTests/ResultsDirectory_Is_Exposed"--results-directory TestResults/issue-6538-overridedotnet test tests/TUnit.PublicAPI/TUnit.PublicAPI.csproj --no-restore(18 passed)dotnet test tests/TUnit.Engine.Tests/TUnit.Engine.Tests.csproj --no-restore(244 passed, 124 skipped)Fixes #6538