---
title: "Implementing Unit Test MetaData using XtUnit custom attributes"
url: "https://osherove.com/blog/2007/6/25/implementing-unit-test-metadata-using-xtunit-custom-attribut.md"
canonical: "https://osherove.com/blog/2007/6/25/implementing-unit-test-metadata-using-xtunit-custom-attribut.html"
published: "2007-06-25T17:10:23"
updated: "2007-06-25T17:10:23"
tags: ["Agile", "Art Of Unit Testing", "Testing Guidelines", "Unit Testing"]
author: "Roy Osherove"
description: "Regarding my last post on xml comments used inside a unit test Here's how you can implement the same \"metadata on a test\" equivalent using XtUnit custom attributes (note that you need to inhering from a custom class for…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Implementing Unit Test MetaData using XtUnit custom attributes

By Roy Osherove June 25, 2007 In [Agile](https://osherove.com/blog/category/agile), [Art Of Unit Testing](https://osherove.com/blog/category/art-of-unit-testing), [Testing Guidelines](https://osherove.com/blog/category/testing-guidelines), [Unit Testing](https://osherove.com/blog/category/unit-testing)

**Historical article** · Originally published June 25, 2007; technical details may be outdated.

Regarding my last post on [xml comments used inside a unit test](http://weblogs.asp.net/rosherove/archive/2007/06/25/unit-test-tip-encode-test-data-as-part-of-your-test-xml-comments.aspx) Here's how you can implement the same "metadata on a test" equivalent using [XtUnit custom attributes](http://weblogs.asp.net/rosherove/archive/2004/10/05/238201.aspx) (note that you need to inhering from a custom class for this):

```
using NUnit.Framework;
using XtUnit.Framework.Internal;

[TestFixture]
    public class CustomDataAttributes:TestFixtureBase
    {
        [Test]
        [Data("sql","Select * from categories")]
        public void useCustomDataAttributes()
        {
            string actual = DataAttribute.items["sql"];
            string expected = "Select * from categories";
            Assert.AreEqual(expected,actual);
        }
    }

    [AttributeUsage(AttributeTargets.Method)]
    class DataAttribute:ProcessingAttributeBase
    {
        private readonly string data = string.Empty;
        private readonly string name = string.Empty;
        public string Name {get { return name; }}
        public string Data { get { return data; } } 
        public DataAttribute(string name, string data)
        {
            this.data = data;
            this.name = name;
        }


        public static readonly Dictionary<string, string> items =                                         new Dictionary<string, string>();         public static Dictionary<string, string> Items
        {get { return items; }  }

        protected override void OnPreProcess()
        {
            items[name] = data;
        }

        protected override void OnPostProcess()
        {   }
    }
```

## More in Agile

[All posts in Agile](https://osherove.com/blog/category/agile)

- Jul 9, 2007

    ### [Danko On Agile and the Agile Israel Community](https://osherove.com/blog/2007/7/9/danko-on-agile-and-the-agile-israel-community.html)

- Jul 8, 2007

    ### [Introducing Agile Israel Community and blogs site](https://osherove.com/blog/2007/7/8/introducing-agile-israel-community-and-blogs-site.html)

- Jun 25, 2007

    ### [Unit Test Tip: Encode test data as part of your test xml comments](https://osherove.com/blog/2007/6/25/unit-test-tip-encode-test-data-as-part-of-your-test-xml-comm.html)

- Jun 25, 2007

    ### [ThreadTester with new Ability: StopWhenTrue() and thread polling](https://osherove.com/blog/2007/6/25/threadtester-with-new-ability-stopwhentrue-and-thread-pollin.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
