How to create an NUnit test project that is also a self-running console app .exe

  1. Create your NUnit Test project as a Windows Console Application, not as a Class Library.
  2. Then make your main Program look like this:
    public class Program
        static void Main(string[] args)
                new[]{Assembly.GetExecutingAssembly().Location }
        [TestCase("Aa - Bb")]
        public void WhenValidatingForename_should_accept_valid_characters(string validInput)
            var result= new ClassUnderTest().Validate(validInput);
        public void WhenValidatingForename_should_reject_invalid_characters(string invalidInput)
            var result= new ClassUnderTest().Validate(invalidInput);
  3. Then, add a reference not only to nunit.framework.dll but also to nunit-console-runner.dll

You now have a self-running executable that runs all your tests, but still behaves in the usual way in a build script, or when running tests inside Visual Studio with TestRunner or Resharper or similar.
NB You may need to check if your build scripts are hard-coded to expect a Test project to be a .dll.

2 thoughts on “How to create an NUnit test project that is also a self-running console app .exe”

  1. I am in the process of figuring this part out I am using VS2019 Community Edition and I can tell the coding is different now then back in 2012.
    I have about 70 NUnit test classes set up for Selenium Automated testing on a website using
    Chrome, IE and Mozilla. Could you please help update me on what I need to do?

    1. Sorry I haven’t used selenium in NUnit for a few years, but if you got to this page from googling, add ‘selenium’ to your search?

Leave a Reply

Your e-mail address will not be published. Required fields are marked *