VS 2010 Test Runner error “The agent process was s

2019-01-30 00:18发布

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:

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.

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.

17条回答
女痞
2楼-- · 2019-01-30 00:46

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.

查看更多
时光不老,我们不散
3楼-- · 2019-01-30 00:47

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’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.

查看更多
姐就是有狂的资本
4楼-- · 2019-01-30 00:50

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.

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

查看更多
Evening l夕情丶
5楼-- · 2019-01-30 00:51

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.

~MyClass()
{
    try
    {
        // Some Code
    }
    catch (Exception e)
    {
        // Log the exception so it's not totally hidden
        // Console.WriteLine(e.ToString());
    }
}
查看更多
乱世女痞
6楼-- · 2019-01-30 00:53

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.

查看更多
The star\"
7楼-- · 2019-01-30 00:53

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.

查看更多
登录 后发表回答