Search Results for

    Show / Hide Table of Contents

    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

    1. This attribute inherits from PropertyAttribute and sets the Description property.
    2. Only one description can be applied per element (AllowMultiple = false).
    3. If both the [Description] attribute and the Description property on [Test]/[TestFixture] are used, the [Description] attribute takes precedence.
    4. Descriptions are useful for generating readable test reports and documentation.

    See Also

    • Property Attribute
    • Author Attribute
    • Category Attribute
    • Edit this page
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0