VS 2010 Test Runner error “The agent process was stopped while the test was running.”

前端 未结 19 1338
醉话见心
醉话见心 2020-12-22 21:13

In Visual Studio 2010, I have a number of unit tests. When I run multiple tests at one time using test lists, I sometimes reveive the following error for one or more of the

相关标签:
19条回答
  • 2020-12-22 21:25

    For finding out where the exception was thrown click on the hyperlink "Test Run Error" next to the exclamation icon in the Test Results window. A window with the stack trace is opened.

    This helps a lot to track down the error!

    0 讨论(0)
  • 2020-12-22 21:25

    The problem can also be triggered by an Exception or Stackoverflow in Constructor of a TestClass.

    0 讨论(0)
  • 2020-12-22 21:25

    For anyone happening upon this old question and wondering what's being thrown from their thread(s), here's a tip. Using Task.Run (as opposed to, say, Thread.Start) will report child thread exceptions much more reliably. In short, instead of this:

    Thread t = new Thread(FunctionThatThrows);
    t.Start();
    t.Join();
    

    Do this:

    Task t = Task.Run(() => FunctionThatThrows());
    t.Wait();
    

    And your error logs should be much more useful.

    0 讨论(0)
  • 2020-12-22 21:27

    This error was caused by a Finalizer for me as well.
    The Finalizer was actaully calling some DB code which wasn't mocked out. Took me a while to find it as it wasn't a class I wrote and the reference to it was burred quite a few classes deep.

    0 讨论(0)
  • 2020-12-22 21:29

    I was having this problem, and it turned out to be a problem in my code which the Test Framework wasn't catching properly. A little accidental refactoring had left me with this code:

    public void GetThingy()
    {
        this.GetThingy();
    }
    

    This is of course an infinite recursion, and caused a StackOverflowException (I guess). What this caused was the dreaded: "The agent process was stopped while the test was running."

    A quick code inspection showed me the problem, and my tests are now running fine. Hope this helps - might be worth inspecting the code looking for issues, or maybe extracting a bit into a console app and checking it works properly there.

    0 讨论(0)
  • 2020-12-22 21:29

    As this error can have many different causes, I'd like to add another one for completeness of this thread.

    If all your tests are aborting as described by the OP, the cause might be a wrong project configuration. In my case the target framework was set to .NET Framework 3.5. Setting it to a higher version through the project properties page (tab Application) resolved the issue.

    0 讨论(0)
提交回复
热议问题