Search The Blog
Latest Posts
Twitter: @RoyOsherove
About this site

TDD in .NET Online Course

TDD and BDD in Ruby Online Course



This site aims to connect all the dots of my online activities - from tools, books blogs and twitter accounts, to upcoming conferences, engagements and user group talks.

« Ubuntu's #1 bug report | Main | Unit Test Tip: Encode test data as part of your test xml comments »

Implementing Unit Test MetaData using XtUnit custom attributes

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 this):


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

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

    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)
   = data;
   = 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()
        {   }

PrintView Printer Friendly Version

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
Web Analytics