Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix "The active test run was aborted" in Visual Studio's Test Explorer?

"Run All" from "Test Explorer" does not complete (VS2017 Enterprise) anymore. It stalls with Passed (411), Not Run (309). The counts vary a little, usually roughly half and half.

The output window (Visual Studio | Output tab | Show output from: Tests) contains the following error message:

"The active test run was aborted. Reason: Unhandled Exception: System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain."

The tests continue to run fine in ReSharper (720 of 720 pass). R# is where I usually run my tests. I jump over to Microsoft's "Test Explorer" when I am trying to Analyze Code Coverage (though the tests stall with or without code coverage). It (Analyze Code Coverage) worked as recently as 5/15/2018 (and at least a half dozen to a dozen times before that). enter image description here

like image 809
dthal Avatar asked Jun 04 '18 18:06

dthal


3 Answers

The Microsoft test runner was being tripped up by a single unit test class that happened to have Task.Run() calls such as the following:

    var task = Task.Run(async () =>
    {
        <various code>
    });

These tests were missing calls to task.Wait() to wait for each task to finish before exiting the test.

(This appears to trip up the Microsoft test runner but not the ReSharper test runner. Specifically, the Microsoft Test Runner aborts the sln test run and skips 300+ tests. ReSharper was able to run all tests without incident.)

Aside: The reason for the varied behavior on Windows 7 versus Windows 10 is because the test class was for a Windows 10 sensitive 3rd party control/library.

like image 94
dthal Avatar answered Oct 16 '22 08:10

dthal


Check the tests output pane for more details - open the output window and select "Tests" option from the "Show output from" combo box.

In my case, my tests project was targeting a version of .NET core I didn't have installed. I just had to change the project target framework to the correct version and it solved the problem.

like image 24
phil_rawlings Avatar answered Oct 16 '22 07:10

phil_rawlings


Just simple Build -> Clear Solution Help for me.

like image 1
Anonimys Avatar answered Oct 16 '22 08:10

Anonimys