一键导入
nunit-attribute-documentation
// Create and update documentation for NUnit attributes following the established template structure
// Create and update documentation for NUnit attributes following the established template structure
| name | NUnit Attribute Documentation |
| description | Create and update documentation for NUnit attributes following the established template structure |
This skill describes how to create and update documentation for NUnit attributes.
Each attribute documentation file in docs/articles/nunit/writing-tests/attributes/ should follow this structure:
# AttributeName
Brief description of what the attribute does.
## Constructor
```csharp
AttributeName(paramType paramName)
```
| Parameter | Type | Description |
|-----------|------|-------------|
| `paramName` | `Type` | Description of the parameter. Include important notes like valid ranges or default behavior. |
## Properties
| Property | Type | Description | Default |
|----------|------|-------------|---------|
| `PropertyName` | `Type` | Description of the property. | `defaultValue` |
> [!NOTE]
> Version notes if applicable (e.g., "Added in **NUnit 4.5.0**").
## Applies To
Use a table with checkmarks to show where the attribute can be applied:
| Target | Supported |
|--------|-----------|
| Test Methods | ✅ |
| Test Fixtures (Classes) | ✅ |
| Assemblies | ❌ |
Use ✅ (green checkmark) where the attribute applies, ❌ (red X) where it doesn't.
## Example
[!code-csharp[ExampleName](~/snippets/Snippets.NUnit/Attributes/AttributeNameExamples.cs#RegionName)]
## Notes
1. Important behavioral notes
2. Limitations
3. Edge cases
## See Also
* [Related Attribute](relatedattribute.md)
Use a simpler "Usage" section instead of Constructor/Properties:
## Usage
This is a parameterless attribute that can only be applied to [target].
```csharp
[AttributeName]
```
Repository Layout Assumption: This workflow assumes you have cloned both repositories as siblings:
<workspace>/nunit/- The NUnit framework source code (nunit/nunit)<workspace>/docs/- This documentation repository (nunit/docs)Adjust paths below to match your local setup.
Search for the attribute class in the NUnit framework:
# Find the attribute source file (adjust path to your nunit repo location)
grep -r "class AttributeNameAttribute" ../nunit --include="*.cs"
The source is typically at:
<nunit-repo>/src/NUnitFramework/framework/Attributes/AttributeNameAttribute.cs
From the source file, extract:
AttributeUsage to determine valid targets (Class, Method, Assembly)Inherited = true# Find unit tests for the attribute (adjust path to your nunit repo location)
grep -r "AttributeName" ../nunit/src/NUnitFramework/tests --include="*.cs"
Tests are typically at:
<nunit-repo>/src/NUnitFramework/tests/Attributes/AttributeNameAttributeTests.cs
Unit tests provide good examples of usage patterns and edge cases.
Create a new file at:
docs/snippets/Snippets.NUnit/Attributes/AttributeNameAttributeExamples.cs
Follow this pattern:
using NUnit.Framework;
namespace Snippets.NUnit.Attributes
{
public class AttributeNameAttributeExamples
{
#region ExampleName
[TestFixture]
public class ExampleTests
{
[Test]
public void ExampleTest()
{
// Test code that demonstrates the attribute
Assert.That(true, Is.True);
}
}
#endregion
#region AnotherExample
// More examples...
#endregion
}
}
Key points:
#region / #endregion to mark code sections#RegionNameReference snippets using DocFX syntax:
[!code-csharp[ExampleName](~/snippets/Snippets.NUnit/Attributes/AttributeNameExamples.cs#ExampleName)]
Always verify the snippets compile and tests pass. From the docs repository root:
# Build
dotnet build docs/snippets/Snippets.slnx
# Run all tests
dotnet test docs/snippets/Snippets.slnx --no-build
# Run specific tests
dotnet test docs/snippets/Snippets.slnx --no-build --filter "FullyQualifiedName~AttributeNameExamples" --verbosity normal
Mark the attribute as done in docs-improvement-plan.md:
| AttributeName | Done | Brief notes about what was added |
Examples: Retry, Repeat, MaxTime, Order
Examples: Retry (has RetryExceptions), TestCase (has many named parameters)
Examples: SingleThreaded, NonParallelizable, Combinatorial
Examples: Parallelizable (takes ParallelScope), Apartment (takes ApartmentState)
Document the enum values in a table.
When documenting command line usage:
Use appropriate code fences - Use ```shell for command line examples, not ```bash, ```text, or untagged code blocks.
Prioritize dotnet test - Always mention dotnet test before the NUnit console runner, as it is used far more frequently.
Include runsettings equivalents - When mentioning console runner options (like --timeout, --workers, etc.), note that these settings can also be configured for dotnet test via the NUnit adapter's .runsettings file.
Example:
## Command Line Usage
```shell
# dotnet test (via NUnit adapter)
dotnet test --filter "TestCategory=Fast"
# Or via runsettings
dotnet test --settings test.runsettings
# NUnit Console Runner
nunit3-console MyTests.dll --where "cat == Fast"
```
Before marking an attribute as done: