I recently discovered an xUnit configuration value that was super helpful, so thought I’d write up a quick blog post.
Out of the box, xUnit results look like this in Visual Studio Test Explorer:
About half of that is noise, specifically the namespace (xUnitDemo) and the class name (DrivingServiceIsValidAgeToDrive). The namespace isn’t really relevant to the test, and the class name is already available as the parent node above all the tests.
A simple change to your app.config will make this much easier to read.
<?xml version="1.0" encoding="utf-8"?>
<add key="xunit.methodDisplay" value="method"/>
Now when we run we get this:
As an aside. I prefer the naming convention of:
- Test Class Name: <ClassYou’reTesting><MethodYou’reTesting>
- Example above, DrivingService is the class and IsValidAgeToDrive is the method
- Test Method Name: Does<Something>_Given<Scenario>
- Example above, DoesReturnTrue_GivenAgeIs16OrOlder
I’ve found this helps make it crystal clear what you’re testing. As a bonus, it makes it fairly easy to show the names to a BA/Stakeholder to make sure you’re covering all their scenarios.