Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

308
Vistas
Running NUnit tests from code (programatically)

I want to run NUnit tests from my code. To be more specific I have an Web API (.net core) that recieves set of test names that needs to be run and after the run, the endpoint will return set of results.

The tests are in another .dll (another project that's using Microsoft.Playwright and Serilog to log to ElasticSearch - it's .net core also but it has classes marked as [TextFixutre]).

At first, I just wanted to check if the RemoteTestRunner is loading all of my tests here is the demo code:

    [HttpPost]
    [Route("/api/TestSuiteRun/Run")]
    public IActionResult RunTestSuite([FromBody] AutomationAPI.Models.TestSuite testSuite)
    {
        try
        {
            CoreExtensions.Host.InitializeService();
            TestSuiteBuilder builder = new TestSuiteBuilder();
            TestPackage testPackage = new TestPackage(@"C:\Desktop\Automation-v2\Automation-v2\bin\Debug\netcoreapp3.1\Automation-v2.dll");
            RemoteTestRunner remoteTestRunner = new RemoteTestRunner();
            remoteTestRunner.Load(testPackage);
            NUnit.Core.TestSuite suite = builder.Build(testPackage);
            NUnit.Core.TestSuite test = suite.Tests[0] as NUnit.Core.TestSuite;
            var numberOfTests = ((TestFixture)test.Tests[0]).TestCount;

            foreach (TestMethod t in ((TestFixture)test.Tests[0]).Tests)
            {
                Console.WriteLine(t.TestName.Name);
            }
            return StatusCode(200);
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.Message);
            return StatusCode(500);
        }
    }

but I'm ending up with following exception on remoteTestRunner.Load(testPackage) line:

"Could not load type 'System.Runtime.Remoting.Messaging.ILogicalThreadAffinative' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."

and I don't know why is this happening. Any ideas?

As for the second question that I have, is it possible to pass TestCaseSource to the test with RemoteTestRunner or it must be written in the .dll explicitly (before load in the RemoteTestRunner) like this:

    [Test, TestCaseSource(typeof(UserProvider), "ProvideUsers")]
    public async Task ExportPPTTimeTestAsync(User currentUser)
    {...
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I'm guessing you found some instructions for running NUnit programmatically on the web - maybe even some I wrote many years ago. You should always look with suspicion on older articles.

In this case, we know that you are using RemoteTestRunner a class from the core of NUnit V2, which is either legacy or obsolete code depending on how you look at it. The problem with ILogicalThreadAffinitive is just the tip of the iceberg. The nunit.core package will never run modern NUnit3 code, and can't even load a .NET Core assembly.

If you want to run code written against current versions of NUnit under .NET Core on the web, your best bet at this time is to call the NUnit Framework API directly from a driver you create yourself. The driver source code incorporated in the latest version of the NUnit3 Console project on GitHub would give you some idea of how it can be done.

Unfortunately, such a project is kind of a big deal so I can't post sample code for you here. If you decide to try it, start by examining the source code of the NUnit3 framework drivers, which are part of the nunit3 console runner project on GitHub. Post specific questions if you run into problems.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda