0

I currently have an nunit project outputting a class library 'RegressionTests.dll' that opens the Selenium WebDriver and runs a few dozen UI tests. I have created a WinForm app with a button 'Run Tests'. When clicking this button, I want to execute a series of n-unit tests from RegressionTests.dll.

I had gotten this to work on my local machine using Process.Start("nunit3-console.exe, nunit-console RegressionTests.dll"), but realized that it would only work on my local if I had installed nunit3-console as a standalone app. After realizing this, I dug more into the n-unit documentation and discovered the n-unit engine. I have tried leveraging the n-unit3 Engine in order to run it internally but have faced issues with implementation of the ITestEventListener in the WinForm project. I've attached the code to my button here:

Form1.cs

private void btnRun_Click(object sender, EventArgs e)
        {
            TestRunner.Run();
        }

Inside TestRunner.cs, we have this code:

[Extension(Description = "Test Reporter Extension", EngineVersion = "3.11")]
    public class TestRunner : ITestEventListener
    {
        public static void Run()
        {
            ITestEngine engine = TestEngineActivator.CreateInstance();
            TestPackage package = new TestPackage("RegressionTests.dll");
            ITestEventListener testListener = new TestRunner();

            using (ITestRunner runner = engine.GetRunner(package))
            {
                XmlNode result = runner.Run(testListener, TestFilter.Empty);
            }
        }

        public void OnTestEvent(string report)
        {
            throw new NotImplementedException();
        }
    }

Currently, the solution layout is as follows.

  • Solution
    • Regression (project)
      • RegressionTests.dll
      • TestRunner.cs (file that contains my code linked above)
    • SeleniumFormApp
      • Form1.cs (contains button that, upon click, should run Selenium test cases)

How can I leverage n-units Nuget packages to accomplish what I want to here? Is n-unit engine the proper one? If so, how should the ITestEventListener be implemented to accomplish this?

Thank you - please let me know if this is unclear.

McCluskey
  • 25
  • 4
  • What problem are you actually having? What happens when you run this code? – Chris Jul 01 '20 at 21:05
  • 1
    It looks as if your class will throw an exception when it receives the first event, i.e. "Run Started!" – Charlie Jul 01 '20 at 22:49
  • 2
    One exceedingly simple way to run tests from a button is to install the TestCentric GUI runner for NUnit. :-) – Charlie Jul 01 '20 at 22:50

0 Answers0