<p>I would like to be able to add a "message" to a unit test, such that it actually appears within the TestResult.xml file generated by NUnit.  For example, this is currently generated:</p>

<pre><code>&lt;results&gt;
    &lt;test-case name="MyNamespace.Tests.MyTest" executed="True" success="True" time="0.203" asserts="4" /&gt;
&lt;/results&gt;
</code></pre>

<p>I would like to be able to have an additional attribute (or node as the case may be), such as:</p>

<pre><code>&lt;results&gt;
    &lt;test-case name="MyNamespace.Tests.MyTest" executed="True" success="True" time="0.203" asserts="4" message="Tested that some condition was met." /&gt;
&lt;/results&gt;
</code></pre>

<p>The idea is that "message" above would somehow be defined within the test method itself (in my case, generated at run-time).  Is there a property somewhere that I'm missing to be able to do something like this?</p>

[{'answer_id': 44653, 'author': 'Blair Conrad', 'author_id': 1199, 'author_profile': 'https://Stackoverflow.com/users/1199', 'pm_score': 3, 'selected': True, 'text': "<p>This may be missing the point, but how about naming the tests so they indicate what they test - then you may not even need the message. </p>\n\n<p>If it proves to be absolutely necessary, I think you'll need to produce your own testrunner that would (off the top of my head) read an additional attribute off the TestCase and attach it to the output.</p>\n"}, {'answer_id': 159497, 'author': 'Don Kirkby', 'author_id': 4794, 'author_profile': 'https://Stackoverflow.com/users/4794', 'pm_score': 0, 'selected': False, 'text': '<p>I can\'t see anything available at run time, but there are a couple of features that you might want to investigate: the <a href="http://www.nunit.org/index.php?p=description&amp;r=2.4.8" rel="nofollow noreferrer">Description</a> attribute and the <a href="http://www.nunit.org/index.php?p=property&amp;r=2.4.8" rel="nofollow noreferrer">Property</a> attribute both add text to the XML output file. Unfortunately, they\'re both defined at compile time.</p>\n'}, {'answer_id': 339415, 'author': 'Cpt. Jack Sparrow', 'author_id': 43050, 'author_profile': 'https://Stackoverflow.com/users/43050', 'pm_score': 3, 'selected': False, 'text': '<p>In the recent NUnit releases you can do: </p>\n\n<pre><code>Assert.AreEqual(250.00, destination.Balance, "some message here");\n</code></pre>\n\n<p>Where "Some message here" can be a constant message or a message generated at runtime and stored in a string variable. These messages will only appear in the output however if the assertion fails. Usually, however, you only need information about failing tests so I recommend building up a string by adding each previous message and then using that string variable as the message in all of your asserts. This allows you to get all of the information you need from failing tests.</p>\n'}, {'answer_id': 48751457, 'author': 'J-Roel', 'author_id': 5687137, 'author_profile': 'https://Stackoverflow.com/users/5687137', 'pm_score': 0, 'selected': False, 'text': '<p>You can use the TestContext to easily write out any message you want. Here is how I am setup.</p>\n\n<p>Each of my tests are inherited from a testbase class. This removes redundant code.</p>\n\n<pre><code>[TestFixture]\npublic class TestBase\n{\n\n    public IWebDriver driver;\n\n    //[OneTimeSetUp] and [OneTimeTearDown] go here if needed\n\n    [SetUp]\n    public void Setup(){\n         driver = Shortcuts.SetDriver("my browser");\n    }\n\n    [TearDown]\n    public void TearDown()\n    {\n        driver.Quit();\n        Comment("@Result: " + TestContext.CurrentContext.Result.Outcome.ToString());\n    }\n\n    public void Comment(string _comment)\n    {\n        TestContext.Out.WriteLine(_comment);\n    }\n    public void Error(string _error)\n    {\n        TestContext.Error.WriteLine(_error);\n    }\n\n}\n</code></pre>\n\n<p>You can see the bottom two functions write out any message or error in said TestContext. This will work nicely with parallizable tests also.</p>\n\n<p>I can then use that parent class to setup my tests, and write to my console.</p>\n\n<pre><code>//Role Management\npublic class RoleManagementTests : TestBase\n{\n    [TestCase]\n    public void RoleManagement_7777_1()\n    {\n        Comment("Expected: User has the ability to view all roles in the system.");\n        //Test goes here\n    }\n}\n</code></pre>\n\n<p>Now you can see the results in the output (Visual Studio) and in the TestResult.xml using NUnit Console Runner.</p>\n'}]
['https://Stackoverflow.com/questions/44617', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2696/']