Skip to content

ConsiderFixturesAsSpecialTests is broken #5716

@Youssef1313

Description

@Youssef1313

In Playground, I have:

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods

using Microsoft.VisualStudio.TestTools.UnitTesting;

[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]

namespace Playground;

[TestClass]
public class TestClass
{
    [TestMethod]
    [DynamicData(nameof(Data))]
    public void Test3(int a, int b)
    {
    }

    [TestInitialize]
    public void TestInitialize()
    {
        // Initialization code here
    }

    [TestCleanup]
    public void TestCleanup()
    {
        // Cleanup code here
    }

    [ClassInitialize]
    public static void ClassInitialize(TestContext _)
    {
        // Class-level initialization code here
    }

    [ClassCleanup(ClassCleanupBehavior.EndOfClass)]
    public static void ClassCleanup()
    {
        // Class-level cleanup code here
    }

    [AssemblyInitialize]
    public static void AssemblyInitialize(TestContext _)
    {
        // Assembly-level initialization code here
    }

    [AssemblyCleanup]
    public static void AssemblyCleanup()
    {
        // Assembly-level cleanup code here
    }

    public static IEnumerable<(int A, int B)> Data
    {
        get
        {
            yield return (1, 2);
            yield return (3, 4);
        }
    }
}

[TestClass]
public class TestClass2
{
    [TestMethod]
    [DynamicData(nameof(Data))]
    public void Test3(int a, int b)
    {
    }

    [TestInitialize]
    public void TestInitialize()
    {
        // Initialization code here
    }

    [TestCleanup]
    public void TestCleanup()
    {
        // Cleanup code here
    }

    [ClassInitialize]
    public static void ClassInitialize(TestContext _)
    {
    }

    [ClassCleanup(ClassCleanupBehavior.EndOfClass)]
    public static void ClassCleanup()
    {
        throw new Exception("TestClass2.ClassCleanup failed");
    }

    public static IEnumerable<(int A, int B)> Data
    {
        get
        {
            yield return (1, 2);
            yield return (3, 4);
        }
    }
}

If I enable ConsiderFixturesAsSpecialTests and try to run the tests in Playground, I get this:

Image

The class cleanup failure isn't associated to the right node.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: FixturesArea: MSTestIssues with MSTest that are not specific to more refined area (e.g. analyzers or assertions)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions