Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show only method name in Test Explorer in VS 2017 (using xUnit for .NET Core)

I know there is this question:

How can XUnit be configured to show just the method name in the Visual Studio 2015 Test Explorer?

I tried both the solution using XML and the JSON file but the name in Text Explorer Window is still the full name with the class. I want to display the method name only as its hard to read the fully qualified names.

Its stated on this site that you can configure using XML

Configuring xUnit.net with XML

but I can't make the effect I'm expecting happen. I've restarted VS 2017 after adding an app.config file in the test project, but still nothing. Is it different for VS 2017?

like image 958
g_b Avatar asked Aug 02 '17 11:08

g_b


People also ask

Which attribute is used to mark a method as test method in xUnit?

This method is decorated with the Fact attribute, which tells xUnit that this is a test.

How do you write xUnit test cases in .NET core?

To write a test you simply create a public method that returns nothing and then decorate it with the Fact attribute. Inside that method you can put whatever code you want but, typically, you'll create some object, do something with it and then check to see if you got the right result using a method on the Assert class.

Does xUnit work with .NET core?

The xUnit.net test runner that we've been using supports . NET Core 1.0 or later, . NET 5.0 or later, and . NET Framework 4.5.


2 Answers

I had the same issue. I'm doing a project in VS2017 using .NET Standard and solved it by following these steps:

  1. In your tests project, create a file named xunit.runner.json
  2. Add the following to the file: { "methodDisplay" : "method" }
  3. In the Solution Explorer, right-click on xunit.runner.json and select "Properties". Set Copy to Output Directory to "Copy Always".

Taken from this comment.

like image 77
Wes Hampson Avatar answered Jan 03 '23 16:01

Wes Hampson


W. Hampson answer is perfect, but just to inform about other possibility - use DisplayName attribute.

[Fact(DisplayName = "Just simple check")]
public void Check()
{
    Assert.NotNull(_operation);
}

enter image description here

like image 34
Aleksej Vasinov Avatar answered Jan 03 '23 15:01

Aleksej Vasinov