Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display the Test Class name in the Text Explorer in Visual Studio 2012 with c# and xUnit

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.

like image 226
bradgonesurfing Avatar asked Jan 02 '13 10:01

bradgonesurfing


People also ask

How do I open test Explorer in Visual Studio?

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.

Where is the test detail summary in Visual Studio?

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.

How do I run a single test case in Visual Studio?

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.)


2 Answers

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.

like image 71
GaTechThomas Avatar answered Sep 28 '22 05:09

GaTechThomas


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.

like image 40
Yennefer Avatar answered Sep 28 '22 06:09

Yennefer