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

MsTest: Replace DelayedFixtureTearDown special case with ClassCleanupBehavior.EndOfClass #128

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
<group targetFramework=".NETFramework4.6.2">
<dependency id="Reqnroll" version="[$version$]" />
<dependency id="Reqnroll.Tools.MsBuild.Generation" version="[$version$]" />
<dependency id="MSTest.TestFramework" version="2.1.2" />
<dependency id="MSTest.TestFramework" version="2.2.8" />
</group>
<group targetFramework=".NETStandard2.0">
<dependency id="Reqnroll" version="[$version$]" />
<dependency id="Reqnroll.Tools.MsBuild.Generation" version="[$version$]" />
<dependency id="MSTest.TestFramework" version="2.1.2" />
<dependency id="MSTest.TestFramework" version="2.2.8" />
</group>
<group targetFramework="net6.0">
<dependency id="Reqnroll" version="[$version$]" />
<dependency id="Reqnroll.Tools.MsBuild.Generation" version="[$version$]" />
<dependency id="MSTest.TestFramework" version="2.1.2" />
<dependency id="MSTest.TestFramework" version="2.2.8" />
</group>
</dependencies>
</metadata>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ public void TestIgnore(string message)
{
TestInconclusive(message); // there is no dynamic "Ignore" in mstest
}

public bool DelayedFixtureTearDown => true;
}
}
2 changes: 0 additions & 2 deletions Plugins/Reqnroll.NUnit.ReqnrollPlugin/NUnitRuntimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ public void TestIgnore(string message)
{
Assert.Ignore(message);
}

public bool DelayedFixtureTearDown => false;
}
}
2 changes: 0 additions & 2 deletions Plugins/Reqnroll.xUnit.ReqnrollPlugin/XUnitRuntimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ public void TestIgnore(string message)
{
Skip.If(true, message);
}

public bool DelayedFixtureTearDown => false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 0 additions & 16 deletions Reqnroll/Infrastructure/TestExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion Reqnroll/UnitTestProvider/IUnitTestRuntimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ public interface IUnitTestRuntimeProvider
void TestPending(string message);
void TestInconclusive(string message);
void TestIgnore(string message);
bool DelayedFixtureTearDown { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ public void TestIgnore(string message)
{
throw new NotImplementedException();
}

public bool DelayedFixtureTearDown
{
get { throw new NotImplementedException(); }
}
}

public void Dispose()
Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/mstest.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down