---
title: "Unit Test Tip: Encode test data as part of your test xml comments"
url: "https://osherove.com/blog/2007/6/25/unit-test-tip-encode-test-data-as-part-of-your-test-xml-comm.md"
canonical: "https://osherove.com/blog/2007/6/25/unit-test-tip-encode-test-data-as-part-of-your-test-xml-comm.html"
published: "2007-06-25T15:59:07"
updated: "2007-06-25T15:59:07"
tags: ["Agile", "Art Of Unit Testing", "Tips & Tricks", "Unit Testing"]
author: "Roy Osherove"
description: "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…"
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/"
---

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

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), [Tips & Tricks](https://osherove.com/blog/category/tips-tricks), [Unit Testing](https://osherove.com/blog/category/unit-testing)

**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](http://www.bestbrains.dk/dansk.aspx/Artikler/Using_Files_In_Unit_Tests).

Lars Thurop wrote the [CommentReader](http://www.bestbrains.dk/dansk.aspx/Artikler/Using_Files_In_Unit_Tests) 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](https://osherove.com/blog/category/agile)

- 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

    ### [Implementing Unit Test MetaData using XtUnit custom attributes](https://osherove.com/blog/2007/6/25/implementing-unit-test-metadata-using-xtunit-custom-attribut.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)

- Jun 24, 2007

    ### [Agile Israel Conference 2007 - Call For Speakers](https://osherove.com/blog/2007/6/24/agile-israel-conference-2007-call-for-speakers.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/
