Home > Back-end >  Is there a way to quickly find out if a C# class has an xunit test on any of its methods in Visual S
Is there a way to quickly find out if a C# class has an xunit test on any of its methods in Visual S

Time:07-22

If I am looking at a class in Visual Studio, I want to know if any of its methods has a unit test on it. XUnit is being used.

Is there a way to quickly find out if a C# class has a unit test and on which method? Also, if there's a way to find out using Resharper, that would be helpful.

CodePudding user response:

If you are using resharper this gets much easier. Make sure to build your code and then click on Extensions->Resharper->Unit Tests->Cover All Tests menu. This will build the coverage report.

If everything runs without problems and your IDE is configured correctly, it starts reflecting test coverage characteristics -

In your class you will see green lines next to your code to indicate that that part of code is covered -

enter image description here

On top of your method signature you should get the number of relevant tests that call the method -

enter image description here

You can click on the 'X/X passing' menu on top, it will list relevant tests in a popup -

enter image description here

From here you can navigate to individual tests as well as run/debug them.

Also, you can right click inside the function code, in the context menu if you click on 'Show covering tests' menu, IDE populates list of tests associated with that function.

Note that none of these features will work if your code is not building. The IDE and its extension requires metadata that is available only after your code builds successfully and tests are run.

CodePudding user response:

One way would be to simply look at the references to the class and see if any of them are in unit tests.

You can click on the "references" above the class declaration, or mark it and hit F12.

Class references

This doesn't show which methods are referenced, but you can determine if the class is referenced in any tests.

  • Related