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

By Roy Osherove In Agile, Art Of Unit Testing, Tips & Tricks, Unit Testing

Markdown version

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

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

More in Agile

All posts in Agile