Search code examples
c#outputnunit

How do I add Hyperlinking in NUnit Test Output?


I want to be able to add hyperlinks to relevant data in the output for a unit test.

I have the following test:

using NUnit.Framework;

namespace BioFire.PanelSoftware.Service.Tests
{
    [TestFixture]
    public class SimpleTest
    {
        [Test]
        public void Test1()
        {
            Console.WriteLine("www.google.com"); //not hyperlink
            Console.WriteLine(@"C:\Program Files"); //not hyperlink
            throw new Exception("My output window will somehow give me a hyperlink to here.");
        }
    }
}

According to this question, it isn't possible in C#. But it is clearly working for nUnit somehow:

An image showing a hyperlink in the command prompt telling me where the exception was thrown


Solution

  • This is very specific to the terminal you are using and I don't believe anything in C# can achieve clickable text. You can technically use Process.Start() from the System.Diagnostics namespace to trigger the default browser to open the webpage you want, but this isn't a hyperlink and would rather be triggered by your specifications

    If you are running from within an IDE, you would have to look into the underlying shell and try to swap it out for a different profile (ex. this should be easy on VS Code but I'm unsure if Visual Studio can support it). If you are running from cmd line, then try using the new Windows Terminal App as it supports this functionality