Unit Test Tip: Encode test data as part of your test xml comments

What a cool idea, and simple too.

You can encode various test data as XML comments on your test, and then use them in your test by parsing the XML file generated by the compiler. More details here.

Lars Thurop wrote the CommentReader which can enable a test that looks like this:

 

        /// <sample>
        ///        create table Orders ( id int, customer int );
        /// </sample>
        [Test]
        public void TestNonXmlComment()
        {
            string content = CommentReader.GetElement("sample");
            Assert.AreEqual(@"create table Orders ( id int, customer int );",
                              content.Trim());
        }
Published Monday, June 25, 2007 6:59 PM by RoyOsherove

Comments

Monday, June 25, 2007 8:10 PM by ISerializable - Roy Osherove's Blog

# 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

# Better alternative to unit test data. &laquo; Vadim&#8217;s Weblog

Pingback from  Better alternative to unit test data. &laquo; Vadim&#8217;s Weblog

Sunday, July 22, 2007 11:41 PM by Ftorres

# re: Unit Test Tip: Encode test data as part of your test xml comments

I created something similar but based on .NET attribute, named www.quickunit.net.

It is a kind of experimental unit test framework, and I am looking for some feedbacks.