question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Failed to start remote test agent' when using nunit.engine.dll in custom runner

See original GitHub issue
  • Method of installation: NuGet
  • Version of the NUnit Engine: 3.6.1

I’m writing a custom runner app (.NET Framework v4.6.2) and have added the nunit.engine and nunit.engine.api NuGe packages to the project. My project only references nunit.engine.api. I’m following this doc here: https://docs.nunit.org/articles/nunit/technical-notes/nunit-internals/Test-Engine-API.html

Here’s my Program.cs:

internal class Program
{
    public static void Main(string[] args)
    {
        // Get an interface to the engine
        ITestEngine engine = TestEngineActivator.CreateInstance();

        // Create a simple test package - one assembly, no special settings
        TestPackage package = new TestPackage("tests.dll");
        
        // Get a runner for the test package
        ITestRunner runner = engine.GetRunner(package);
        
        var testEventListener = new MyTestEventListener();

        // Run all the tests in the assembly
        XmlNode testResult = runner.Run(testEventListener, TestFilter.Empty);
    }
}

When I execute the program I get this:

Unhandled Exception: NUnit.Engine.NUnitEngineException: Failed to start remote test agent.
   at NUnit.Engine.Services.TestAgency.OnAgentExit(Process process, Guid agentId)
   at NUnit.Engine.Services.TestAgency.<>c__DisplayClass7_0.<LaunchAgentProcess>b__0(Object sender, EventArgs e)
   at System.Diagnostics.Process.OnExited()
   at System.Diagnostics.Process.RaiseOnExited()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)

Then a second later I get:

Unhandled Exception: System.TypeLoadException: Could not load type 'NUnit.Engine.NUnitEngineUnloadException' from assembly 'nunit.engine.api, Version=3.0.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb'.
   at NUnit.Common.ExceptionHelper.FlattenExceptionHierarchy(Exception exception)
   at NUnit.Common.ExceptionHelper.BuildMessageAndStackTrace(Exception exception)
   at NUnit.Engine.Runners.ProcessRunner.RunTests(ITestEventListener listener, TestFilter filter)
   at NUnit.Engine.Runners.MasterTestRunner.RunTests(ITestEventListener listener, TestFilter filter)
   at NUnit.Engine.Runners.MasterTestRunner.Run(ITestEventListener listener, TestFilter filter)
   at Zzz.Program.Main(String[] args) in C:\Zzz\Program.cs:line xx

I tried running my tests.dll with nunit3-console and it seems to work fine so I don’t think the tests assembly is at fault.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
CharliePoolecommented, Sep 2, 2020

@kyle-v-51 The console output is pretty straightforward based on the XML result as well as various XML-formatted events that are fired while the test runs. Take a look at the code in the console project or in the NUnitLite assembly (different code that does basically the same thing)

1reaction
kyle-v-51commented, Sep 1, 2020

Looks like updating the engine/API NuGet package to latest fixed the issue.

As an aside, I see my report comes back as XML – is there a way to get all the same output I see when running a test via the nunit console too?

Read more comments on GitHub >

github_iconTop Results From Across the Web

The NUnit 3 driver encountered an error while executing ...
i have the same error "unable to cast" with the latest: nunit 3.13.0; nunit.console.runner 3.12.0; nunit3TestAdapter 3.17.0 : NUnit.Engine.
Read more >
Exception thrown running NUnit.ConsoleRunner against ...
When we use Nunit.Console 3.7.0 to run tests from command line like this: ./nunit3-console.exe C:\dev\Path\To\Test\Project\bin\Release\Utilities.Tests.dll
Read more >
Console and Engine Release Notes
The nunit3-console.exe runner executes under the .NET Framework but is able to launch .NET Core agents and communicate with them over a TCP...
Read more >
Pre 3.5 Release Notes
The nunit3-console runner cannot run tests that reference the portable build. You may run such tests using NUnitLite or a platform-specific runner.
Read more >
Getting Started with the NUnit Engine
Getting Started with the NUnit Engine. Building your own test runner? This guide covers the basics of getting up and running.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found