visual-studio VS 2010 测试运行器错误“测试运行时代理进程已停止。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2810012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VS 2010 Test Runner error "The agent process was stopped while the test was running."
提问by driis
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 tests:
在 Visual Studio 2010 中,我有许多单元测试。当我使用测试列表一次运行多个测试时,我有时会为一个或多个测试重新发现以下错误:
The agent process was stopped while the test was running.
测试运行时代理进程已停止。
It is never the same test failing, and if I try to run the test again, it succeeds.
永远不会是相同的测试失败,如果我再次尝试运行测试,它就会成功。
I found this bug report on Connect, which seems to be the same problem, but it does not offer a solution.
我在 Connect 上发现了这个错误报告,这似乎是同样的问题,但它没有提供解决方案。
Has anyone else seen this behaviour ? How I can avoid it ?
有没有其他人看到过这种行为?我怎样才能避免它?
Edit
编辑
I am still experiencing this bug, and so is many of my colleagues on the same software/hardware setup. I have evaluated the answers so far, but they don't resolve the problem. I am starting a bounty for a solution to this problem.
我仍然遇到这个错误,我的许多同事也在遇到相同的软件/硬件设置。到目前为止,我已经评估了答案,但它们并没有解决问题。我开始悬赏来解决这个问题。
采纳答案by satorg
I've just experienced the similar problem: some tests fail and they are different in different test runs. I don't know exactly the reason why it happens, but it began to occur when I added a finalizer to one of my classes. When I disable the finalizer - the problem disappears. When I turn the finalizer on - the problem comes back.
我刚刚遇到了类似的问题:一些测试失败,并且在不同的测试运行中它们是不同的。我不知道它发生的确切原因,但是当我向我的一个类添加终结器时它开始发生。当我禁用终结器时 - 问题就消失了。当我打开终结器时 - 问题又回来了。
Right now I don't know how to overcome this.
现在我不知道如何克服这个。
回答by mafu
This message is caused by an exception on a thread different from the executing test thread. All answers so far boil down to this simple explanation. It is a known bug in Visual Studio not to display any sensible information in that case.
此消息是由与正在执行的测试线程不同的线程上的异常引起的。到目前为止,所有答案都归结为这个简单的解释。在这种情况下,Visual Studio 中的一个已知错误是不显示任何合理的信息。
Visual Studio's test runner totally chokes if a thread other than the executing test thread throws an exception: It gets swallowed and there's no output, no chance to intercept and debug and no nothing except a burned-down smoldering mess that was supposed to be your unit test.
如果执行测试线程以外的线程抛出异常,Visual Studio 的测试运行器将完全窒息:它被吞没,没有输出,没有机会拦截和调试,除了应该是你的单元的烧毁闷烧之外什么都没有测试。
回答by Simon Steele
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."
这当然是无限递归,并导致 StackOverflowException (我猜)。这导致了可怕的:“在测试运行时代理进程被停止。”
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.
快速代码检查向我展示了问题所在,我的测试现在运行良好。希望这会有所帮助 - 可能值得检查代码以查找问题,或者可能将一些内容提取到控制台应用程序中并检查它在那里是否正常工作。
回答by Denise Skidmore
I was able to find the source of my problem by looking in the test result file (/TestResults/*.trx) It provided the full details of the exception that occurred in the background thread, and once I resolved that exception the "agent processed stopped..." error went away.
通过查看测试结果文件 (/TestResults/*.trx),我能够找到问题的根源,它提供了后台线程中发生的异常的完整详细信息,一旦我解决了该异常,“代理处理停止...”错误消失了。
In my case I was unintentionally launching the GUI in my unit test, which eventually caused a System.ComponentModel.InvalidAsynchronousStateException to be thrown.
就我而言,我无意中在单元测试中启动了 GUI,这最终导致抛出 System.ComponentModel.InvalidAsynchronousStateException。
So my .trx file contained:
所以我的 .trx 文件包含:
<RunInfo computerName="DT-1202" outcome="Error" timestamp="2013-07-29T13:52:11.2647907-04:00">
<Text>One of the background threads threw exception:
System.ComponentModel.InvalidAsynchronousStateException: An error occurred invoking the method. The destination thread no longer exists.
at System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle waitHandle)
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
...
</Text>
</RunInfo>
This didn't provide any information on what test caused the error, but it did show me where the exception was, which was very useful.
这没有提供任何关于什么测试导致错误的信息,但它确实向我展示了异常在哪里,这非常有用。
回答by Mike Zboray
This message is typically generated when the test process crashes and can happen when there is an unhandled exception on a background thread, a stack overflow occurs, or an explicit call to Process.GetCurrentProcess().Kill()or Environment.Exit. Another possible cause is an access violation in unmanaged code.
此消息通常在测试进程崩溃时生成,并且可能在后台线程上出现未处理的异常、发生堆栈溢出或显式调用Process.GetCurrentProcess().Kill()或时发生Environment.Exit。另一个可能的原因是非托管代码中的访问冲突。
Something no one has mentioned is that there may be additional information in the event log. Usually you will not get much information on why the test crashed in the results, however in the event of an unhandled exception on a background thread, then the test framework writes details to the Application event log with source VSTTExecution. If there is no information written to the event log then it is likely one of the other causes listed above.
没有人提到的事情是事件日志中可能有其他信息。通常,您不会在结果中获得有关测试崩溃原因的太多信息,但是如果后台线程上出现未处理的异常,则测试框架会将详细信息写入应用程序事件日志,并使用源 VSTTExecution。如果没有信息写入事件日志,则可能是上面列出的其他原因之一。
回答by Gon
I encountered the same Problem and solved it while Removing
我遇到了同样的问题并在删除时解决了它
Environment.Exit(0);
So i am pretty sure, that this error occurs while your test or method under test, is causing the executing process to terminate.
所以我很确定,这个错误发生在你的测试或被测方法时,导致执行过程终止。
回答by bendewey
In my case the solution was resolved by checking the Output Window.
在我的情况下,解决方案是通过检查输出窗口解决的。
'QTAgent32.exe' (Managed (v4.0.30319)): Loaded 'C:\TestResults\bdewey_XXXXXX072 2011-01-11 17_00_40\Out\MyCode.dll', Symbols loaded. E, 9024, 9, 2011/01/11, 17:00:46.827, XXXXX072\QTAgent32.exe, Unhandled Exception Caught, reporting through Watson: [Exception message]
“QTAgent32.exe”(托管(v4.0.30319)):加载“C:\TestResults\bdewey_XXXXXX072 2011-01-11 17_00_40\Out\MyCode.dll”,加载符号。E, 9024, 9, 2011/01/11, 17:00:46.827, XXXXX072\QTAgent32.exe, Unhandled Exception Caught, 通过 Watson 报告:[异常消息]
In my case I had a FileSystemWatcher that was throwing an error on a seperate thread.
就我而言,我有一个 FileSystemWatcher,它在单独的线程上抛出错误。
回答by Brent VanderMeide
Thanks for posting the question. I just ran into this problem and figured out a cause that you may be running into.
感谢您发布问题。我刚刚遇到了这个问题,并找出了您可能遇到的原因。
An asynchronous exception may have occurred
可能发生了异步异常
During my test setup, I create an object that queues a worker thread in the thread pool. If I run through debugging fast enough my code passes.
在我的测试设置期间,我创建了一个对象,该对象将线程池中的工作线程排队。如果我调试得足够快,我的代码就会通过。
If the worker thread kicks off and has an error BEFORE the test setup completes, then I get a result of Aborted with no reasoning.
如果工作线程在测试设置完成之前启动并出现错误,那么我会得到 Aborted 的结果而没有任何推理。
If the worker thread kicks off and has an error AFTER the test has begun, then I get a result of : Error - The agent process was stopped while the test was running.
如果工作线程在测试开始后启动并出现错误,那么我会得到以下结果:错误 - 测试运行时代理进程已停止。
Important to note: this is a component that I use throughout several of my tests. If the test framework encounters too many of these errors it aborts the rest of the tests.
重要的是要注意:这是我在几个测试中都使用的组件。如果测试框架遇到太多这样的错误,它会中止其余的测试。
Hope this helps
希望这可以帮助
回答by Jarrod Chesney
I added try/catch blocks to the descructor ~ClassName(){} that were defined in any class involved in my tests. This fixed the problem for me.
我将 try/catch 块添加到在我的测试中涉及的任何类中定义的解析器 ~ClassName(){} 中。这为我解决了问题。
~MyClass()
{
try
{
// Some Code
}
catch (Exception e)
{
// Log the exception so it's not totally hidden
// Console.WriteLine(e.ToString());
}
}
回答by BlackTuareg
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!
这对追踪错误有很大帮助!

