microsoft / testfx

MSTest framework and adapter
MIT License
714 stars 253 forks source link

[Ignore] on base classes does not work on derived classes. #3681

Closed Bruhst closed 6 days ago

Bruhst commented 3 weeks ago

In version 3.5.2 the [Ignore] attribute on base classes does no work on the derived classes.

Example:

[TestClass]

if !DEBUG

[Ignore]

endif

public abstract class DebugTestBase
{
   ...
}

[TestClass]

if !RELEASE

[Ignore]

endif

public abstract class ReleaseTestBase
{
   ...
}

[TestClass] public class MyDebugTest1 : DebugTestBase { ... }

[TestClass] public class MyReleaseTest1 : ReleaseTestBase { ... }

The expected behavior is that in RELEASE builds only unit tests deriving from ReleaseTestBase would be executed and in DEBUG builds only unit tests deriving from DebugTestBase.

In version 3.4.3 the behavior was exactly like expected but now we switched to version 3.5.2 and all unit tests are executed regardless which build configuration is used and regardless which is the base class of the unit test.

Evangelink commented 3 weeks ago

Hi @Bruhst,

Would it be possible to get a full reproducer? I have tried with the following code:

TestProject1.csproj:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <LangVersion>latest</LangVersion>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="MSTest" Version="3.4.3" />
    </ItemGroup>

</Project>

Test1.cs:

namespace TestProject1
{
    [Ignore]
    [TestClass]
    public abstract class Test1
    {
        [TestMethod]
        public void TestMethod1()
        {
        }
    }

    [TestClass]
    public class Test2 : Test1
    {
        [TestMethod]
        public void Test1()
        {
        }
    }
}

and I do see the 2 tests executed in 3.4.3

Passed! - Failed: 0, Passed: 2, Skipped: 0, Total: 2, Duration: [521ms]
microsoft-github-policy-service[bot] commented 2 weeks ago

Hello @Bruhst, This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.