When I run my tests today with xUnit v2, I typically use a naming convention like:
[Fact(DisplayName= "Method Will Do Something")]
public void Method_Will_Do_Something() { }
What extensibility point can I plug into that will allow me set my test display name based on the naming conventions of my test method?
Naming your tests The name of your test should consist of three parts: The name of the method being tested. The scenario under which it's being tested. The expected behavior when the scenario is invoked.
Important note: xUnit.net uses the presence of the interface IClassFixture<> to know that you want a class fixture to be created and cleaned up. It will do this whether you take the instance of the class as a constructor argument or not.
The [Fact] attribute declares a test method that's run by the test runner. From the PrimeService. Tests folder, run dotnet test . The dotnet test command builds both projects and runs the tests. The xUnit test runner contains the program entry point to run the tests.
xUnit.net is a free, open source, community-focused unit testing tool for the . NET Framework. Written by the original inventor of NUnit v2, xUnit.net is the latest technology for unit testing C#, F#, VB.NET and other . NET languages. xUnit.net works with ReSharper, CodeRush, TestDriven.NET and Xamarin.
The simplest way: Custom fact attribute, discoverer, and test case.
Example: https://github.com/xunit/samples.xunit/tree/master/RetryFactExample
For your custom test case, derive from XunitTestCase
and override the Initialize()
method. After calling base.Initialize()
, set the DisplayName
property appropriately.
You can see the default behavior for XunitTestCase
here: https://github.com/xunit/xunit/blob/master/src/xunit.execution/Sdk/Frameworks/XunitTestCase.cs
Create a custom class for your fact
public sealed class MyFactAttribute : FactAttribute
{
public MyFactAttribute([CallerMemberName] string memberName = null)
{
DisplayName = memberName;
}
}
And use as follows
[MyFact]
public void FileSystemProvider_Sync()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With