Conversation
There was a problem hiding this comment.
Pull request overview
Adds documentation and runnable snippets for several NUnit 4.6-era attributes and updates the attributes TOC so the new pages appear in the docs.
Changes:
- Add new attribute docs pages:
[UnhandledExceptionHandling],[NoTests],[NetPlatform],[TestAssemblyDirectoryResolve] - Add corresponding C# snippet/example files used by DocFX
[!code-csharp]inclusions - Extend
[TestCase]docs with a new section for genericTestCaseattributes and update the attributes TOC
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj | Updates NUnit package reference version for the snippets test project |
| docs/snippets/Snippets.NUnit/Attributes/UnhandledExceptionHandlingAttributeExamples.cs | Adds snippet examples for [UnhandledExceptionHandling] |
| docs/snippets/Snippets.NUnit/Attributes/TestCaseGenericExamples.cs | Adds snippet examples for generic TestCase attributes |
| docs/snippets/Snippets.NUnit/Attributes/TestAssemblyDirectoryResolveAttributeExamples.cs | Adds snippet examples for [TestAssemblyDirectoryResolve] |
| docs/snippets/Snippets.NUnit/Attributes/NoTestsAttributeExamples.cs | Adds snippet examples for [NoTests] |
| docs/snippets/Snippets.NUnit/Attributes/NetPlatformAttributeExamples.cs | Adds snippet examples for [NetPlatform] |
| docs/articles/nunit/writing-tests/attributes/unhandledexceptionhandling.md | New docs page for [UnhandledExceptionHandling] |
| docs/articles/nunit/writing-tests/attributes/testassemblydirectoryresolve.md | New docs page for [TestAssemblyDirectoryResolve] |
| docs/articles/nunit/writing-tests/attributes/notests.md | New docs page for [NoTests] |
| docs/articles/nunit/writing-tests/attributes/netplatform.md | New docs page for [NetPlatform] |
| docs/articles/nunit/writing-tests/attributes/toc.yml | Adds new attribute pages to the attributes TOC |
| docs/articles/nunit/writing-tests/attributes/testcase.md | Adds “Generic TestCase Attributes” section and snippet references |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
docs/snippets/Snippets.NUnit/Attributes/TestAssemblyDirectoryResolveAttributeExamples.cs
Outdated
Show resolved
Hide resolved
| // Any unhandled exception on background threads will cause this test to fail | ||
| // This is the default behavior | ||
| var task = Task.Run(() => | ||
| { | ||
| // Work that completes successfully | ||
| Thread.Sleep(10); | ||
| }); | ||
| task.Wait(); | ||
| Assert.Pass(); |
There was a problem hiding this comment.
The example is framed as handling unhandled background-thread exceptions, but Task.Run(...); task.Wait(); observes any exception on the main test thread. That means this pattern won’t illustrate (and may contradict) what [UnhandledExceptionHandling] affects per the warning in the docs. Consider adjusting the snippet/comment to use a truly unhandled background exception scenario (e.g., a fire-and-forget thread) or rewording to avoid implying Wait() is relevant here.
docs/snippets/Snippets.NUnit/Attributes/UnhandledExceptionHandlingAttributeExamples.cs
Outdated
Show resolved
Hide resolved
docs/articles/nunit/writing-tests/attributes/unhandledexceptionhandling.md
Outdated
Show resolved
Hide resolved
| // Returns empty when certain conditions aren't met | ||
| if (Environment.GetEnvironmentVariable("RUN_CONDITIONAL_TESTS") == "true") | ||
| { | ||
| yield return "test1"; | ||
| yield return "test2"; | ||
| } | ||
| // Otherwise yields nothing - test will be Inconclusive |
There was a problem hiding this comment.
This example’s behavior depends on the RUN_CONDITIONAL_TESTS environment variable, which can make snippet test results vary between environments/CI runs. Prefer keeping snippet fixtures deterministic (e.g., base the condition on a local constant or provide two explicit sources) so the documented outcome is consistent.
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" /> | ||
| <PackageReference Include="NUnit" Version="4.5.1" /> | ||
| <PackageReference Include="NUnit" Version="4.6.0-*" /> |
There was a problem hiding this comment.
Using a floating prerelease version (4.6.0-*) makes restores non-deterministic and will fail if no matching prerelease exists on the configured NuGet feeds. Prefer pinning a specific NUnit version (e.g., 4.6.0) or using a stable floating patch range (e.g., 4.6.*) if you intentionally want updates.
| <PackageReference Include="NUnit" Version="4.6.0-*" /> | |
| <PackageReference Include="NUnit" Version="4.6.0" /> |
docs/snippets/Snippets.NUnit/Attributes/TestCaseGenericExamples.cs
Outdated
Show resolved
Hide resolved
docs/snippets/Snippets.NUnit/Attributes/TestCaseGenericExamples.cs
Outdated
Show resolved
Hide resolved
…esolveAttributeExamples.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…lingAttributeExamples.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…nhandling.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…s.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…s.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
New Attributes documentation b7ef520
Fixes #1161