diff --git a/CHANGELOG.md b/CHANGELOG.md index bacad49b7..bbbfa808b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Fix: #111 @ignore attribute is not inherited to the scenarios from Rule * Support for JSON files added to SpecFlow.ExternalData * Fix: #120 Capture ExecutionContext after every binding invoke +* MsTest: Use ClassCleanupBehavior.EndOfClass instead of custom implementation (preparation for MsTest v4.0) # v1.0.1 - 2024-02-16 diff --git a/Plugins/Reqnroll.MSTest.Generator.ReqnrollPlugin/Reqnroll.MSTest.nuspec b/Plugins/Reqnroll.MSTest.Generator.ReqnrollPlugin/Reqnroll.MSTest.nuspec index 63360359a..94e7a2a45 100644 --- a/Plugins/Reqnroll.MSTest.Generator.ReqnrollPlugin/Reqnroll.MSTest.nuspec +++ b/Plugins/Reqnroll.MSTest.Generator.ReqnrollPlugin/Reqnroll.MSTest.nuspec @@ -19,17 +19,17 @@ - + - + - + diff --git a/Plugins/Reqnroll.MSTest.ReqnrollPlugin/MsTestRuntimeProvider.cs b/Plugins/Reqnroll.MSTest.ReqnrollPlugin/MsTestRuntimeProvider.cs index ee8be201d..b6db73f7d 100644 --- a/Plugins/Reqnroll.MSTest.ReqnrollPlugin/MsTestRuntimeProvider.cs +++ b/Plugins/Reqnroll.MSTest.ReqnrollPlugin/MsTestRuntimeProvider.cs @@ -19,7 +19,5 @@ public void TestIgnore(string message) { TestInconclusive(message); // there is no dynamic "Ignore" in mstest } - - public bool DelayedFixtureTearDown => true; } } \ No newline at end of file diff --git a/Plugins/Reqnroll.NUnit.ReqnrollPlugin/NUnitRuntimeProvider.cs b/Plugins/Reqnroll.NUnit.ReqnrollPlugin/NUnitRuntimeProvider.cs index 081fe7439..a54df615e 100644 --- a/Plugins/Reqnroll.NUnit.ReqnrollPlugin/NUnitRuntimeProvider.cs +++ b/Plugins/Reqnroll.NUnit.ReqnrollPlugin/NUnitRuntimeProvider.cs @@ -19,7 +19,5 @@ public void TestIgnore(string message) { Assert.Ignore(message); } - - public bool DelayedFixtureTearDown => false; } } \ No newline at end of file diff --git a/Plugins/Reqnroll.xUnit.ReqnrollPlugin/XUnitRuntimeProvider.cs b/Plugins/Reqnroll.xUnit.ReqnrollPlugin/XUnitRuntimeProvider.cs index c84221bb0..99efacd30 100644 --- a/Plugins/Reqnroll.xUnit.ReqnrollPlugin/XUnitRuntimeProvider.cs +++ b/Plugins/Reqnroll.xUnit.ReqnrollPlugin/XUnitRuntimeProvider.cs @@ -19,7 +19,5 @@ public void TestIgnore(string message) { Skip.If(true, message); } - - public bool DelayedFixtureTearDown => false; } } \ No newline at end of file diff --git a/Reqnroll.Generator/UnitTestProvider/MsTestGeneratorProvider.cs b/Reqnroll.Generator/UnitTestProvider/MsTestGeneratorProvider.cs index d38b6b0c8..beb0cb675 100644 --- a/Reqnroll.Generator/UnitTestProvider/MsTestGeneratorProvider.cs +++ b/Reqnroll.Generator/UnitTestProvider/MsTestGeneratorProvider.cs @@ -13,6 +13,8 @@ public class MsTestGeneratorProvider : IUnitTestGeneratorProvider protected internal const string PROPERTY_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute"; protected internal const string TESTFIXTURESETUP_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute"; protected internal const string TESTFIXTURETEARDOWN_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute"; + protected internal const string CLASSCLEANUPBEHAVIOR_ENUM = "Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior"; + protected internal const string CLASSCLEANUPBEHAVIOR_ENDOFCLASS = "EndOfClass"; protected internal const string TESTSETUP_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute"; protected internal const string TESTTEARDOWN_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute"; protected internal const string IGNORE_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.IgnoreAttribute"; @@ -112,7 +114,9 @@ public virtual void SetTestClassInitializeMethod(TestClassGenerationContext gene public void SetTestClassCleanupMethod(TestClassGenerationContext generationContext) { generationContext.TestClassCleanupMethod.Attributes |= MemberAttributes.Static; - CodeDomHelper.AddAttribute(generationContext.TestClassCleanupMethod, TESTFIXTURETEARDOWN_ATTR); + // [Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute(Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfClass)] + var attribute = CodeDomHelper.AddAttribute(generationContext.TestClassCleanupMethod, TESTFIXTURETEARDOWN_ATTR); + attribute.Arguments.Add(new CodeAttributeArgument(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(CLASSCLEANUPBEHAVIOR_ENUM), CLASSCLEANUPBEHAVIOR_ENDOFCLASS))); } diff --git a/Reqnroll.TestProjectGenerator/Reqnroll.TestProjectGenerator/ProjectBuilder.cs b/Reqnroll.TestProjectGenerator/Reqnroll.TestProjectGenerator/ProjectBuilder.cs index ef8329902..92f716480 100644 --- a/Reqnroll.TestProjectGenerator/Reqnroll.TestProjectGenerator/ProjectBuilder.cs +++ b/Reqnroll.TestProjectGenerator/Reqnroll.TestProjectGenerator/ProjectBuilder.cs @@ -16,7 +16,7 @@ public class ProjectBuilder public const string NUnit3TestAdapterPackageName = "NUnit3TestAdapter"; public const string NUnit3TestAdapterPackageVersion = "3.17.0"; private const string XUnitPackageVersion = "2.4.2"; - private const string MSTestPackageVersion = "2.1.2"; + private const string MSTestPackageVersion = "2.2.8"; private const string InternalJsonPackageName = "SpecFlow.Internal.Json"; private const string InternalJsonVersion = "1.0.8"; private readonly BindingsGeneratorFactory _bindingsGeneratorFactory; diff --git a/Reqnroll/Infrastructure/TestExecutionEngine.cs b/Reqnroll/Infrastructure/TestExecutionEngine.cs index b201dc037..e36fe9649 100644 --- a/Reqnroll/Infrastructure/TestExecutionEngine.cs +++ b/Reqnroll/Infrastructure/TestExecutionEngine.cs @@ -141,15 +141,6 @@ public virtual async Task OnTestRunEndAsync() public virtual async Task OnFeatureStartAsync(FeatureInfo featureInfo) { - // if the unit test provider would execute the fixture teardown code - // only delayed (at the end of the execution), we automatically close - // the current feature if necessary - if (_unitTestRuntimeProvider.DelayedFixtureTearDown && FeatureContext != null) - { - await OnFeatureEndAsync(); - } - - _contextManager.InitializeFeatureContext(featureInfo); _testThreadExecutionEventPublisher.PublishEvent(new FeatureStartedEvent(FeatureContext)); @@ -159,13 +150,6 @@ public virtual async Task OnFeatureStartAsync(FeatureInfo featureInfo) public virtual async Task OnFeatureEndAsync() { - // if the unit test provider would execute the fixture teardown code - // only delayed (at the end of the execution), we ignore the - // feature-end call, if the feature has been closed already - if (_unitTestRuntimeProvider.DelayedFixtureTearDown && - FeatureContext == null) - return; - await FireEventsAsync(HookType.AfterFeature); if (_reqnrollConfiguration.TraceTimings) diff --git a/Reqnroll/UnitTestProvider/IUnitTestRuntimeProvider.cs b/Reqnroll/UnitTestProvider/IUnitTestRuntimeProvider.cs index 702bba205..4cebfa4b0 100644 --- a/Reqnroll/UnitTestProvider/IUnitTestRuntimeProvider.cs +++ b/Reqnroll/UnitTestProvider/IUnitTestRuntimeProvider.cs @@ -5,6 +5,5 @@ public interface IUnitTestRuntimeProvider void TestPending(string message); void TestInconclusive(string message); void TestIgnore(string message); - bool DelayedFixtureTearDown { get; } } } \ No newline at end of file diff --git a/Tests/Reqnroll.RuntimeTests/Infrastructure/TestRunContainerBuilderTests.cs b/Tests/Reqnroll.RuntimeTests/Infrastructure/TestRunContainerBuilderTests.cs index 8a5b9fc97..fe91167ce 100644 --- a/Tests/Reqnroll.RuntimeTests/Infrastructure/TestRunContainerBuilderTests.cs +++ b/Tests/Reqnroll.RuntimeTests/Infrastructure/TestRunContainerBuilderTests.cs @@ -111,11 +111,6 @@ public void TestIgnore(string message) { throw new NotImplementedException(); } - - public bool DelayedFixtureTearDown - { - get { throw new NotImplementedException(); } - } } public void Dispose() diff --git a/docs/integrations/mstest.md b/docs/integrations/mstest.md index e108f8aaa..664466ad6 100644 --- a/docs/integrations/mstest.md +++ b/docs/integrations/mstest.md @@ -1,6 +1,6 @@ # MSTest -Reqnroll supports MsTest V2. +Reqnroll supports MsTest V2 (NuGet Version 2.2.8 or higher). Documentation for MSTest can be found [here](https://docs.microsoft.com/en-us/visualstudio/test/unit-test-your-code?view=vs-2019).