Xunit: Proposing addition of a new xunit.methodDisplay option named MethodThenClass

Created on 6 Jun 2017  路  3Comments  路  Source: xunit/xunit

This idea proposes the addition of a new xunit.methodDisplay option named MethodThenClass. It will output the important test method name first, followed by its namespace + class.

The two existing method display options are 'classAndMethod' or just 'method', as noted here in the docs.

The proposed _MethodThenClass_ option stems from this Tweet in which test method names can be run off the right side of the screen leaving behind a slew of namespace information in the cropped view. Sometimes the only other option of displaying just a method name is too short because it doesn't provide enough context when multiple namespaces and classes are involved.

The proposed _MethodThenClass_ option would provide a hybrid display approach that surfaces the important test method name first on the line, including the complete long name context following on it.

I'm undecided about what format to propose for a _MethodThenClass_ option but am prone to the familiar comma syntax used by .NET developers when formulating fully qualified type names, therefore a format like: 'methodname, namespace + class'.

For example, the default ClassAndMethod display option value having method name at the end like

Microsoft.AspNetCore.Sockets.Common.Test.Internal.Formatters.ServerSentEventsParserTests.ParseSSEMessageFailureCases"

could instead be displayed with the proposed MethodThenClass option with test name first as:

"ParseSSEMessageFailureCases, Microsoft.AspNetCore.Sockets.Common.Test.Internal.Formatters.ServerSentEventsParserTests".

Looking for feedback about if this idea is viable and needed or wanted, how it might be manifested.
TIA

Core framework Discussion

Most helpful comment

How about reversing the namespace, class, and method name segment order?
I often write tests like:

class ComponentTest {
  class BuildOutput extends ComponentTest {
    class WhenInputIsMalformed extends BuildOutput {
      [Fact] void ThrowsException() { }
    }
  }
}

Typically it prints ComponentTest.BuildOutput.WhenInputIsMalformed.ThrowsException failed, but ThrowsException.WhenInputIsMalformed.BuildOutput.ComponentTest would decrease the need to scan in the middle of the line.

All 3 comments

How about reversing the namespace, class, and method name segment order?
I often write tests like:

class ComponentTest {
  class BuildOutput extends ComponentTest {
    class WhenInputIsMalformed extends BuildOutput {
      [Fact] void ThrowsException() { }
    }
  }
}

Typically it prints ComponentTest.BuildOutput.WhenInputIsMalformed.ThrowsException failed, but ThrowsException.WhenInputIsMalformed.BuildOutput.ComponentTest would decrease the need to scan in the middle of the line.

Due to coding conventions, namespaces in our projects are rather long (think Company.Product.AreaOfTheProduct.Component...). I would love to have "shortClassAndMethod", which would display just name of the class + method.

Example:

namespace Company.Product.AreaOfTheProduct.Component {
    class ComponentTest {
        class WhenInputIsMalformed {
            [Fact] void ThrowsException() { }
        }
    }
}

...would produce name

ComponentTest.WhenInputIsMalformed.ThrowsException

Subset of #1429.

Was this page helpful?
0 / 5 - 0 ratings