Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting unit testing code into XML Comment [duplicate]

I am trying to comment an API (.Net) that I am exposing to a customer. I am doing this by using XML comments, and extracting via SandCastle.

This is all fine and dandy, however I have unittesting for the API, and thought the code from these would be good to place in the example tags.

So does anyone know of a good way to extract unit test code and place in the example tags? Or does anyone have better ideas?

Of course I redistribute the unit tests with the API, but it would be good to have them in the documentation.

like image 492
khebbie Avatar asked Dec 18 '25 16:12

khebbie


1 Answers

I am using NUnit and Sandcastle Help File Builder. Please take a look at Sandcastle Help File Builder documentation about The Code Block Component.

Here is an example how I place unit tests code in the example tag:

    /// <summary>
    /// Returns a string representation of an object.
    /// </summary>
    /// <returns>Comma separated string.</returns>
    /// <example>
    /// <code source="UnitM.CentrallProcessingLib.Tests\Data\CSVDataRowTests.cs" region="ToString_a" />
    /// </example>
    public override string ToString()
    {
        return this.Data;
    }

Here is a referenced unit test (CSVDataRowTests.cs) (it should be inside the #region section):

  #region ToString_a

    [Test]
    public void ToString_a()
    {
        CSVDataRow res = new CSVDataRow 
        {
            Data = "1;2;3"
        };

        Assert.AreEqual(res.ToString(), res.Data);
    }

  #endregion

Best regards.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!