-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClassCleanup not called in base class #1889
Comments
Hi @pi3k14, I confirm that something is not working fine here. I have tried the various options and I confirm that the base is never called. |
I cannot find a single place where this works (I am writing to Trace.WriteLine, to make sure the output collector is simply not missing it). Looking at the fixes from PRs the fix that was supposed to implement and fix this is in 2.0.0 and 2.1.0 ( #577 #660 ) , still that does not work for me, so maybe I am just doing it wrong?
<!-- file mstest1.csproj -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
</ItemGroup>
</Project>
// file UnitTest1.cs
using System.Diagnostics;
namespace mstest1;
[TestClass]
public class BaseClass
{
[ClassCleanup(inheritanceBehavior: InheritanceBehavior.BeforeEachDerivedClass)]
public static void ClassCleanupBase()
{
Trace.WriteLine("base cleanup");
}
}
[TestClass]
public class UnitTest1 : BaseClass
{
[TestMethod]
public void TestMethod1()
{
Trace.WriteLine("Test method");
}
[ClassCleanup(inheritanceBehavior: InheritanceBehavior.BeforeEachDerivedClass)]
public static void ClassCleanup()
{
Trace.WriteLine("class cleanup");
}
} No matter the combination of the class cleanup I simply don't see Trace.WriteLine("base cleanup"); in my output. |
Interesting... I was looking at why our acceptance tests are working and noticed that we have also a |
Ok so the problem is way bigger than expected... We need a huge refactoring of the class cleanup handling. |
As per @Evangelink comment above Workaround Declare your class cleanup method with BeforeEachDerivedClass inheritance behavior, and define a dummy class initialize method with same setting.
|
Describe the bug
MSTest.TestFramework 3.0.4
ClassCleanup method in base class not called
Additional context
Verified in debuger.
Also mentioned in Class Initialize inheritance #143
The commented method works.
The text was updated successfully, but these errors were encountered: