-
Notifications
You must be signed in to change notification settings - Fork 291
Fix EndOfClass cleanup for DataRow #1020
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
Fix EndOfClass cleanup for DataRow #1020
Conversation
|
This seems to fix the issue, but I won't manage to add tests. Please add some @Haplois. This was my repro, the Display name change in the attribute is not necessary.: <!-- file TestProject3\TestProject3.csproj -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="99.99.99-dev" />
<PackageReference Include="MSTest.TestFramework" Version="99.99.99-dev" />
<!--<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />-->
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>
</Project>
// file TestProject3\UnitTest1.cs
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Diagnostics;
[assembly: ClassCleanupExecution(cleanupBehavior: ClassCleanupBehavior.EndOfClass)]
namespace TestProject3
{
[TestClass]
public class UnitTest1
{
static long Start;
static UnitTest1()
{
Start = Stopwatch.GetTimestamp();
}
[ClassCleanup]
public static void ClassCleanup() {
Console.WriteLine("cleanup");
}
[TestMethod(displayName: "TestMethod1")]
[DataRow(1)]
[DataRow(2)]
public void TestMethod1(int _)
{
// the cleanup output should be on the test with the bigger number
// because it needs to run on the last test
Console.WriteLine(Stopwatch.GetTimestamp() - Start);
}
}
[TestClass]
public class UnitTest2
{
static long Start;
static UnitTest2()
{
Start = Stopwatch.GetTimestamp();
}
[ClassCleanup]
public static void ClassCleanup()
{
Console.WriteLine("cleanup");
}
[TestMethod(displayName: "TestMethod1")]
public void TestMethod1()
{
Console.WriteLine(Stopwatch.GetTimestamp() - Start);
}
[TestMethod(displayName: "TestMethod2")]
public void TestMethod2()
{
Console.WriteLine(Stopwatch.GetTimestamp() - Start);
}
}
} |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
volleyms
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I wonder why you would use the display name which could be any string, even as duplicate within a test class, instead of the unique method name... just my 2 cents...
Haplois
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests to be added later on...
|
@volleyms, DisplayName should be unique; but a method could be executed multiple times if it's bound to a test data source and each execution considered as a test case. |
Fix cleanup for DataRow, to remove tests from the dictionary by using the same name (DisplayName) as what they were added. This affects DataRow tests and probably any test that uses DisplayName. Because then the entry in the hashmap and the key used to remove it (MethodName) are not the same.
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1448552