0

I've a c# visual studio project in which i make tests with xunit.

Now the test explorer shows tests by their namespaces like this:

enter image description here

I don't want that redundant cluttering in the test names.

I know I can annotate the methods to set testnames like this:

public class WhenCreating : GivenConnection
    {
        [Fact(DisplayName = nameof(GivenConnection) + "." + nameof(WhenCreating ) + "." + nameof(ItAppliesFromCity))]
        public void ItAppliesFromCity()

But this is still very redundant as I would have to annotate each method with the same prefix. Is there any way to influence the test name generation? Like ParentClass.SubClass.Method ?

update: To write it more expressive: i still want to have the name of the parent-class(es) in the test names. not only the method name which can be done via app.config

Boas Enkler
  • 12,264
  • 16
  • 69
  • 143
  • 1
    Please refer to the http://stackoverflow.com/questions/32351210/how-can-xunit-be-configured-to-show-just-the-method-name-in-the-visual-studio-20 topic to accomplish your goal. – Pasick Feb 21 '17 at 09:41
  • I don't think this duplicate as it doesn't add the parentclasses to the Test name . in the example above (GivenConnection) – Boas Enkler Feb 21 '17 at 09:48

1 Answers1

1

Set xunit.methodDisplay in your App.config file.

<configuration>
  <appSettings>
    <add key="xunit.methodDisplay" value="method"/>
  </appSettings>
</configuration>
Pasick
  • 384
  • 2
  • 7