ClassCleanup declared on a base type not correctly triggered
See original GitHub issueDescription
When the ClassCleanup attribute is declared on a base type with ClassCleanupBehavior.EndOfClass, it still triggered at end of assembly.
Steps to reproduce
Run this code:
[TestClass]
public class TestClassBase
{
[ClassInitialize(InheritanceBehavior.BeforeEachDerivedClass)]
public static void BeforeClsBase(TestContext testContext)
{
Log.Message("ClassInitialize - TestClassBase");
}
[ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass, ClassCleanupBehavior.EndOfClass)]
public static void AfterClsBase()
{
Log.Message("ClassCleanup - TestClassBase");
}
}
[TestClass]
public class TestClassDerivedA : TestClassBase
{
[TestMethod]
public void TestMethod()
{
Log.Message("Test Method A");
}
}
[TestClass]
public class TestClassDerivedB : TestClassBase
{
[TestMethod]
public void TestMethod()
{
Log.Message("Test Method B");
}
}
Expected behavior
ClassCleanup is triggered at the end of class, according to ‘ClassCleanupBehavior.EndOfClass’
Actual behavior
Log output:
ClassInitialize - TestClassBase
Test Method A
ClassInitialize - TestClassBase
Test Method B
ClassCleanup - TestClassBase
ClassCleanup - TestClassBase
Environment
VS 2019 MSTest.TestAdapter: 2.2.10 MSTest.TestFramework: 2.2.10
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
ClassInitialize attribute in unit test based class not called
When declaring ClassInitialize attribute on a method, the method has to be static, public, void (or Task, if async) and should take a...
Read more >ClassCleanup attribute not working as expected
Microsoft's Documentation - ClassCleanupAttribute Class says, "Identifies a method that contains code to be used after all the tests in the test ...
Read more >xUnit Testing Tutorial: Unit Testing With Selenium C# | ...
xUnit is an open-source unit testing framework for .NET. This xUnit testing tutorial will help you learn how to run unit testing with ......
Read more >JUnit 5 User Guide
Declares a custom display name for the test class or test method. Such annotations are not inherited. @DisplayNameGeneration. Declares a custom ...
Read more >Thinking in Java, 3rd ed. Revision 3.0: 6: Reusing Classes
As seen in scrub( ), it's possible to take a method that's been defined in the base class and modify it. In this...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @3s-ap! Thank you for reporting this issue! I have managed to reproduce the behavior.
@3s-ap v3.0.1 is now released, feel free to give it a go and get back to us if you find anything wrong.