question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClassCleanup declared on a base type not correctly triggered

See original GitHub issue

Description

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

AB#1677601

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Evangelinkcommented, Sep 29, 2022

Hi @3s-ap! Thank you for reporting this issue! I have managed to reproduce the behavior.

0reactions
Evangelinkcommented, Dec 20, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found