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

前端 未结 19 1337
醉话见心
醉话见心 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:15

    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());
        }
    }
    
    0 讨论(0)
  • 2020-12-22 21:16

    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

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

    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.

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

    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.

    In my case I was unintentionally launching the GUI in my unit test, which eventually caused a System.ComponentModel.InvalidAsynchronousStateException to be thrown.

    So my .trx file contained:

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

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

    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]

    In my case I had a FileSystemWatcher that was throwing an error on a seperate thread.

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

    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.

    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.

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