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

Remove class/assembly initialization messages from logs. #1339

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using ObjectModelUnitTestOutcome = Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel.UnitTestOutcome;
Expand Down Expand Up @@ -302,6 +303,8 @@ public void RunClassInitialize(TestContext testContext)
finally
{
IsClassInitializeExecuted = true;
Debug.Assert(testContext is ITestContext, "TestContext is null.");
(testContext as ITestContext)?.ClearDiagnosticMessages();
}
}
}
Expand Down
35 changes: 6 additions & 29 deletions test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public void ValidateTestRunLifecycle_net462()
private void ValidateTestRunLifecycle(string targetFramework)
{
InvokeVsTestForExecution(new[] { targetFramework + "\\" + Assembly }, targetFramework: targetFramework);
Verify(RunEventsHandler.PassedTests.Count == 15); // the inherit class tests are called twice
Verify(RunEventsHandler.PassedTests.Count == 15); // The inherit class tests are called twice.

int assemblyInitCalledCount = 0;
int classInitCalledCount = 0;
int classCleanupCalledCount = 0;
int assemblyCleanupCalledCount = 0;

Expand All @@ -36,21 +37,20 @@ private void ValidateTestRunLifecycle(string targetFramework)
assemblyInitCalledCount += isTestMethodMessageContains("AssemblyInit was called") ? 1 : 0;
classCleanupCalledCount += isTestMethodMessageContains("ClassCleanup was called") ? 1 : 0;
assemblyCleanupCalledCount += isTestMethodMessageContains("AssemblyCleanup was called") ? 1 : 0;
classInitCalledCount += isTestMethodMessageContains("ClassInitialize was called") ? 1 : 0;
}

Verify(assemblyInitCalledCount == 1);

// Assembly and Class cleanup don't appear in the logs because they happen after retrieving the result.
// TODO: https://github.com/microsoft/testfx/issues/1328
// Assembly and Class init/cleanup logs don't appear in the tests' results.
Verify(classCleanupCalledCount == 0);
Verify(assemblyCleanupCalledCount == 0);
Verify(assemblyInitCalledCount == 0);
Verify(classInitCalledCount == 0);

var caseClassCleanupWithCleanupBehaviorEndOfAssembly = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("SuiteLifeCycleTestClass_ClassCleanupWithCleanupBehaviorEndOfAssembly"));
Verify(caseClassCleanupWithCleanupBehaviorEndOfAssembly.Outcome == Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed);
Verify(caseClassCleanupWithCleanupBehaviorEndOfAssembly.Messages.Single().Text.Contains(
targetFramework == "net6.0" ?
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -60,7 +60,6 @@ Dispose was called
"""
:
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -73,7 +72,6 @@ Dispose was called
Verify(caseClassCleanupWithCleanupBehaviorEndOfClass.Messages.Single().Text.Contains(
targetFramework == "net6.0" ?
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -83,7 +81,6 @@ Dispose was called
"""
:
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -96,7 +93,6 @@ Dispose was called
Verify(caseClassInitializeWithInheritanceBehaviorBeforeEachDerivedClassAndClassCleanupWithInheritanceBehaviorNone.Messages.Single().Text.Contains(
targetFramework == "net6.0" ?
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -106,7 +102,6 @@ Dispose was called
"""
:
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -119,7 +114,6 @@ Dispose was called
Verify(caseClassInitializeWithInheritanceBehaviorNoneAndClassCleanupWithInheritanceBehaviorBeforeEachDerivedClass.Messages.Single().Text.Contains(
targetFramework == "net6.0" ?
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -129,7 +123,6 @@ Dispose was called
"""
:
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -142,7 +135,6 @@ Dispose was called
Verify(caseClassCleanupWithNoProperty.Messages.Single().Text.Contains(
targetFramework == "net6.0" ?
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -152,7 +144,6 @@ Dispose was called
"""
:
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -165,8 +156,6 @@ Dispose was called
Verify(caseInheritClassWithCleanupInheritanceBehaviorBeforeEachDerivedClass.Messages.Single().Text.Contains(
targetFramework == "net6.0" ?
"""
ClassInitialize was called
Derived ClassInitialize was called
Ctor was called
Derived class Ctor was called
TestInitialize was called
Expand All @@ -179,8 +168,6 @@ Dispose was called
"""
:
"""
ClassInitialize was called
Derived ClassInitialize was called
Ctor was called
Derived class Ctor was called
TestInitialize was called
Expand Down Expand Up @@ -224,7 +211,6 @@ Dispose was called
Verify(caseInheritClassWithCleanupInheritanceBehaviorNone.Messages.Single().Text.Contains(
targetFramework == "net6.0" ?
"""
Derived ClassInitialize was called
Ctor was called
Derived class Ctor was called
TestInitialize was called
Expand All @@ -237,7 +223,6 @@ Dispose was called
"""
:
"""
Derived ClassInitialize was called
Ctor was called
Derived class Ctor was called
TestInitialize was called
Expand Down Expand Up @@ -281,7 +266,6 @@ Dispose was called
Verify(caseClassInitializeAndCleanupWithInheritanceBehaviorNone.Messages.Single().Text.Contains(
targetFramework == "net6.0" ?
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -291,7 +275,6 @@ Dispose was called
"""
:
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -304,7 +287,6 @@ Dispose was called
Verify(caseClassInitializeAndCleanupWithInheritanceBehaviorBeforeEachDerivedClass.Messages.Single().Text.Contains(
targetFramework == "net6.0" ?
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -314,7 +296,6 @@ Dispose was called
"""
:
"""
ClassInitialize was called
Ctor was called
TestInitialize was called
TestMethod was called
Expand All @@ -327,7 +308,6 @@ Dispose was called
Verify(caseInheritClassWithClassInitializeInheritanceBehaviorBeforeEachDerivedClassAndClassCleanupInheritanceBehaviorNone.Messages.Single().Text.Contains(
targetFramework == "net6.0" ?
"""
Derived ClassInitialize was called
Ctor was called
Derived class Ctor was called
TestInitialize was called
Expand All @@ -340,7 +320,6 @@ Dispose was called
"""
:
"""
Derived ClassInitialize was called
Ctor was called
Derived class Ctor was called
TestInitialize was called
Expand Down Expand Up @@ -384,7 +363,6 @@ Dispose was called
Verify(caseInheritClassWithClassInitializeInheritanceBehaviorNoneAndClassCleanupInheritanceBehaviorBeforeEachDerivedClass.Messages.Single().Text.Contains(
targetFramework == "net6.0" ?
"""
Derived ClassInitialize was called
Ctor was called
Derived class Ctor was called
TestInitialize was called
Expand All @@ -397,7 +375,6 @@ Dispose was called
"""
:
"""
Derived ClassInitialize was called
Ctor was called
Derived class Ctor was called
TestInitialize was called
Expand Down