Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A handy testing method to serialize an object as JSON for MSTEST output
/// <summary>
/// Helper to output as JSON
/// </summary>
public static class TestOutputHelper
{
/// <summary>
/// Emit an object as json
/// </summary>
/// <param name="output">ITestOutputHelper</param>
/// <param name="o">object</param>
/// <param name="title">(optional) Title</param>
public static void AsJson(this TestContext output, object o, string title = null)
{
var json = JsonConvert.SerializeObject(o);
if (string.IsNullOrWhiteSpace(title)) output.WriteLine("{0}", json);
else output.WriteLine("{0}\n{1}", title, json);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.