Skip to content

Change method display name #1280

Answered by thomhurst
Arthri asked this question in Q&A
Nov 24, 2024 · 1 comments · 7 replies
Discussion options

You must be logged in to vote

This is achievable in 0.4.1 by inheriting from the DisplayNameFormatterAttribute and plugging in custom logic.

Here's an example using the library Humanizer:

[HumanizerDisplayName]
public class HumanizerDisplayNameTests
{
    [Test]
    public void This_test_name_is_formatted_nicely()
    {
        Console.WriteLine(TestContext.Current!.GetTestDisplayName());
    }
    
    public class HumanizerDisplayNameAttribute : DisplayNameFormatterAttribute
    {
        protected override string FormatDisplayName(TestContext testContext)
        {
            return testContext.TestDetails.TestName.Humanize();
        }
    }
}

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@Arthri
Comment options

@thomhurst
Comment options

@Arthri
Comment options

@thomhurst
Comment options

Answer selected by Arthri
@Arthri
Comment options

@thomhurst
Comment options

@Arthri
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants