Skip to content
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 declared on a base type not correctly triggered #1093

Closed
3s-ap opened this issue Apr 27, 2022 · 5 comments
Closed

ClassCleanup declared on a base type not correctly triggered #1093

3s-ap opened this issue Apr 27, 2022 · 5 comments
Assignees
Milestone

Comments

@3s-ap
Copy link

3s-ap commented Apr 27, 2022

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

@Evangelink
Copy link
Member

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

@Evangelink
Copy link
Member

@engyebrahim This issue is somehow related to the various fixes you are doing on init and cleanup methods. Could you please investigate it after you are done with your refactoring?

@engyebrahim
Copy link
Member

engyebrahim commented Dec 1, 2022

Hi @3s-ap! I tried to reproduce the issue using V2.2.10 using TestContext and Console.Write but the messages' order was different than the ones you had.

  1. using TestContext the cleanup logs don't appear.
  2. using Console.Write the cleanup appear at the beginning.

So please can you upload the whole repo to use the log.message() you used in your investigation? Or did you try to use one of the ways I used?

@3s-ap
Copy link
Author

3s-ap commented Dec 1, 2022

Hi @engyebrahim,

I attached a small lib that reproduces the issue. Please inspect the 'bin\debug\net48\log.txt' file after you run all tests.

sources.zip

@Evangelink
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants