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

DataTestMethodAttribute doesn't have a constructor to set display name #2121

Closed
HannoZ opened this issue Jan 18, 2024 · 7 comments
Closed

DataTestMethodAttribute doesn't have a constructor to set display name #2121

HannoZ opened this issue Jan 18, 2024 · 7 comments
Milestone

Comments

@HannoZ
Copy link
Contributor

HannoZ commented Jan 18, 2024

Summary

The TestMethodAttribute has a constructor that allows you to set the DisplayName property. DataTestMethodAttribute inherits from this class, but doesn't have the constructor to provide a display name, so it's impossible to provide an alternative display name for

Background and Motivation

Providing a display name for unit tests is a nice way to have a more descriptive display for your tests. However it is now not possible to do this for DataTestMethod unit tests because the required constructor is not present.
DataRowAttribute does have the ability to set the DisplayName which is nice, but it would be great to also be able to set it for the test itself.

Proposed Feature

I guess it's just a matter of adding
public DataTestMethodAttribute(string? displayName) : base(displayName) { }
(I'm still trying to build the repository without success so I cannot verify this myself yet)

@Evangelink
Copy link
Member

Hi @HannoZ,

Thank you for the report. This indeeds looks like the feature missed some cases, we will work on it (except if you are willing to take care of it).

What's the issue you are facing with building the repository?

@Evangelink Evangelink added this to the 3.3.0 milestone Jan 18, 2024
@HannoZ
Copy link
Contributor Author

HannoZ commented Jan 18, 2024

I would be glad to fix it myself, if I can manage to build the solution. There's a lot of advanced stuff in there so it's not very easy to troubleshoot. First I was having some issues with the .NET 9 alpha SDK, it seemed to be installed by running Build.cmd but it wasn't. So (after some searching) I found the installer on https://github.com/dotnet/installer. That helped to solve a lot of build errors, but there is one left in project FxExtensibility: "The analyzer assembly 'C:\Program Files\dotnet\sdk\9.0.100-alpha.1.24067.14\Sdks\Microsoft.NET.Sdk\codestyle\cs\Microsoft.CodeAnalysis.CSharp.CodeStyle.dll' references version '4.10.0.0' of the compiler, which is newer than the currently running version '4.8.0.0'."
And there is also an issue with uap10.0.16299 which causes a compile error in UWP_UITestMethodAttribute.cs

@Evangelink
Copy link
Member

Thanks! I'll try to improve the build doc page.

hat helped to solve a lot of build errors, but there is one left in project FxExtensibility: "The analyzer assembly 'C:\Program Files\dotnet\sdk\9.0.100-alpha.1.24067.14\Sdks\Microsoft.NET.Sdk\codestyle\cs\Microsoft.CodeAnalysis.CSharp.CodeStyle.dll' references version '4.10.0.0' of the compiler, which is newer than the currently running version '4.8.0.0'."

Interesting, I don't have this even on clean build (git clean -dfx)

And there is also an issue with uap10.0.16299 which causes a compile error in UWP_UITestMethodAttribute.cs

Have you run this script https://github.com/microsoft/testfx/blob/main/eng/Install-WindowsSDK.ps1?

@HannoZ
Copy link
Contributor Author

HannoZ commented Jan 18, 2024

Have you run this script https://github.com/microsoft/testfx/blob/main/eng/Install-WindowsSDK.ps1?

After running this script, all errors are gone!
Which means I can work on a fix myself now 👍🏻

HannoZ added a commit to HannoZ/testfx that referenced this issue Jan 18, 2024
@Evangelink Evangelink modified the milestones: 3.3.0, 3.2.0 Jan 19, 2024
@Evangelink
Copy link
Member

Moved to 3.2.0

@HannoZ
Copy link
Contributor Author

HannoZ commented Feb 2, 2024

Hi @Evangelink Today I tested the new 3.2.0 package. The new constructor with displayname overload is there now, but unfortunately the display name seems to be ignored when the test is actually displayed..
Do I create a new issue for this or do you reopen this one?

public class MyTestClass
{
    [DataTestMethod("This is a data test method")]
    [DataRow("This_is_a_datarow1", DisplayName = "Row 1")]
    [DataRow("This_is_a_datarow2", DisplayName = "Row 2")]
    public void MyDataTestMethod(string input)
    {
        // test code
    }

    [TestMethod("This is a regular test method")]
    public void MyTestMethod()
    {
        // test code
    }
}

image

@Evangelink
Copy link
Member

Damn, sorry I should have looked at adding some integration test. I will create a different issue. Thanks for the report!

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

No branches or pull requests

2 participants