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

9

15

"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

Bill answered 4/6, 2018 at 18:23 Comment(2)
The same exact source code behaved differently on 2 machines in at least 1 parallel test. A Windows 10 Surface tablet ran 771/771 tests without trouble using "Analyze Code Coverage". At the exact same time, a Windows 7 desktop PC failed to run 319 of 771 tests (status "Not Run Tests (319)"). ReSharper test runner always works fine on both machines.Bill
For me, I had a [ClassInitialize] method that did not take in a TestContext parameter.Tweak
B
6

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.

Bill answered 14/6, 2018 at 0:22 Comment(1)
I had a similar issue. I changed my test method by removing async from the method signature and removed await from the call to the method I was testing and used .Result instead, then it worked. The error messaging was not very helpful.Arlyn
S
16

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.

Stainless answered 12/11, 2020 at 13:2 Comment(1)
Not surprisingly, this can also occur in VS 2019, if there's a problem with a test/code being tested. In my case, there was a stack overflow in my code (can happen when working with only 5 hours sleep), so the tests were being aborted.Scissile
B
6

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.

Bill answered 14/6, 2018 at 0:22 Comment(1)
I had a similar issue. I changed my test method by removing async from the method signature and removed await from the call to the method I was testing and used .Result instead, then it worked. The error messaging was not very helpful.Arlyn
S
3

Just a simple

Build -> Clean Solution

helped me.

Selector answered 23/10, 2019 at 20:32 Comment(3)
You probably meant Build -> Clean SolutionImplement
Think that localization depend on VS version, so yes Clear/Clean the sameSelector
that does not help if output/test shows TestPlatformException: Could not find testhostSolana
M
3

My test was declared as

public async void DoSomething(...)

To fix it, I changed it to:

public async Task DoSomething(...)
Milurd answered 10/4 at 6:34 Comment(0)
K
1

Check Output window after setting output window drop down to tests.

My issue was that one of the test was doing an infinite loop.

Kitty answered 31/1 at 1:34 Comment(0)
C
1

This is a long shot but I had my method marked as private which caused it to abort

    [TestMethod]
    private async Task ComputeDailyMetricsTest()

versus

    [TestMethod]
    public async Task ComputeDailyMetricsTest()
Cartierbresson answered 16/5 at 18:20 Comment(0)
A
0

An infinite recursion was causing this problem for me.

The stack overflow exception does not get reported as a test failure.(Probably because there's no stack frame left to report it).

Hope this helps someone get unstuck quicker.

Algae answered 28/2 at 20:8 Comment(0)
S
0

In my case, I had an Xunit test class but I was missing the [Fact] attribute and I kept trying to debug the test by clicking Ctrl R + T.

Just make sure you are not missing the [Fact] attribute like so:

[Fact]
public void My_Test_Method() { ... }
Sphenic answered 5/4 at 11:45 Comment(0)
H
0

same issue here managed to track it down eventually to accidentally having 2 methods tagged as [AssemblyCleanup]

resorted the tried and tested commment everything out and readd a test at a time until it stopped running at which point i knew the issue was the cleanup and at that point was just case of tracking down why it was failing with no errors

more generically if your test are not running check all the none test code Initialise, cleanup, etc if its failing to run then the error is most likely in one of these

Hydrogen answered 15/7 at 7:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.