I'm using xUnit with the built in Text Explorer in visual studio 2012. It would be nice to scope the name of the test with the name of the class so if I have for example
namespace Foo.Bar {
class CatTests {
[Fact]
public void Test1(){
}
}
}
I would see in the test explorer
Foo.Bar.CatTests.Test1
as the name of the test. Is this possible in any way? At the moment I only see
Test1
which is a pain if I have lots of Test1 cases spread across multiple namespaces and test classes.
If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.
View Tests and Test Lists in Test Explorer If the Test Explorer pane is not opened in your Visual Studio, you can access this as follows: in Visual Studio 2015 and 2017 - Test -> Windows -> Test Explorer; in Visual Studio 2019 and later - Test -> Test Explorer; or use keyboard shortcut Ctrl + E, T.
According to this answer (By Jon Skeet no less) it is possible in Visual studio natively too. To debug a single test: Click on a test method name, then press Ctrl+R, Ctrl+T. (Or go to Test / Debug / Tests in Current Context.)
Currently we use FactAttribute's DisplayName:
[Fact(DisplayName = "Foo.Bar.CatTests.Test1")]
It does not appear that this can be done automatically, but it certainly would be nice if it did.
You can change how tests are shown in the Test Explorer by using a specific configuration file (xunit.runner.json
) as described in this SO answer.
Additionally, you may need to change the grouping settings in the IDE in order to show the class name and not the full path.
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