Description
DescriptionAttribute is used to apply descriptive text to a test, test fixture, or assembly. The description appears in test output and XML result files, providing additional context about what a test does.
Constructor
DescriptionAttribute(string description)
| Parameter | Type | Description |
|---|---|---|
description |
string |
The descriptive text for the test or fixture. |
Applies To
| Test Methods | Test Fixtures (Classes) | Assembly |
|---|---|---|
| ✅ | ✅ | ✅ |
Alternative Syntax
Description can also be specified as a named parameter on [TestFixture] or [Test] attributes:
[TestFixture(Description = "Tests for user authentication")]
[Test(Description = "Verifies login with valid credentials")]
Examples
Fixture Level
[TestFixture]
[Description("Tests for the shopping cart functionality")]
public class ShoppingCartTests
{
[Test]
public void AddItem_EmptyCart_ItemAdded()
{
Assert.Pass();
}
}
Method Level
[TestFixture]
public class PaymentTests
{
[Test]
[Description("Verifies that valid credit card payments are processed successfully")]
public void ProcessPayment_ValidCard_ReturnsSuccess()
{
Assert.Pass();
}
[Test]
[Description("Ensures expired cards are rejected with appropriate error")]
public void ProcessPayment_ExpiredCard_ReturnsError()
{
Assert.Pass();
}
}
Using Named Parameter Syntax
[TestFixture(Description = "Integration tests for the user registration flow")]
public class UserRegistrationTests
{
[Test(Description = "Tests complete registration with all required fields")]
public void Register_AllFieldsValid_CreatesUser()
{
Assert.Pass();
}
}
Notes
- This attribute inherits from
PropertyAttributeand sets theDescriptionproperty. - Only one description can be applied per element (
AllowMultiple = false). - If both the
[Description]attribute and theDescriptionproperty on[Test]/[TestFixture]are used, the[Description]attribute takes precedence. - Descriptions are useful for generating readable test reports and documentation.