Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can resharper jump to the file that contains the unit tests?

Tags:

c#

resharper

Is it possible to somehow link or use some convention so I can jump between my unit tests for a given class?

Also, creating short cuts for jumping between the interface, the implementations?

(keyboard shortcuts)

Example:

IUserService UserService UserServiceTests

It would be great if I can somehow link these together so I can jump to any of these files while in any one of them currently.

like image 999
codecompleting Avatar asked Sep 21 '11 15:09

codecompleting


People also ask

How do I run unit tests with ReSharper?

Ctrl+U R / Debug Unit Tests. Ctrl+U D on the toolbar. To run all tests in the session, click Run Current Session. Ctrl+U Y on the toolbar or alternatively, choose ReSharper | Unit Tests | Run Current Session from the main menu.

Does ReSharper include dotCover?

dotCover integrates into Visual Studio 2010, 2012, 2013, 2015, 2017, 2019, and 2022. After installing dotCover with or without any other dotUltimate tools and opening Visual Studio, you will find dotCover commands under the ReSharper | Unit Tests and ReSharper | Cover in the main menu.

How do you unit test a session?

To open this window, press Ctrl+Alt+T or choose ReSharper | Windows | Unit Test Sessions from the main menu. The window also opens automatically each time you run or debug unit tests from the current document or from the project/solution, create a new test session, or add tests to a test session.


3 Answers

I just implemented that feature in TestLinker, which is a ReSharper 2016.1 extension. It is available to install from the ReSharper Gallery.

Demo

like image 110
Matthias Avatar answered Oct 20 '22 15:10

Matthias


Is it possible to somehow link or use some convention so I can jump between my unit tests for a given class?

To jump between unit tests for a given class, launch ReSharper's Find Usages on the class name, and as soon as you have results in the Find Results tool window, group them in a way that helps focus on usages in a particular part of your code base - for example, by project and type. This will let detect usages in your test project. From there, you can quickly jump from Find Results to actual usages in code. As an alternative, you can use ReSharper's Go to Usages of Symbol that works in a similar way but displays search results in a pop-up menu instead of flushing them to Find Results.

If your test classes contain metadata showing which business logic they're covering, this would help even better in differentiating the usages you need. For example, if you're using MSpec, test classes are marked with the Subject attribute: [Subject(typeof (MyCoveredClass))] This is handy because usages within this attribute are very visible, and navigating to them leads you directly to declarations of your test classes: Find MSpec test classes that cover a particular class

With NUnit and MSTest, this is a bit more complicated as their attributes take strings as parameters, like this: [TestProperty("TestKind", "MyCoveredClass")]. In order to find such a usage of MyCoveredClass, you'll have to use ReSharper's Find Usages Advanced and turn on the Textual occurrences option.

Also, creating short cuts for jumping between the interface, the implementations?

As to jumping within an inheritance chain, ReSharper provides multiple options to do that, including Type Hierarchy (ReSharper > Inspect > Type Hierarchy) and Go to Implementation (ReSharper > Navigate > Go to Implementation):

Navigating throughout inheritance chains with Go to Implementation and/or Type Hierarchy

like image 3
Jura Gorohovsky Avatar answered Oct 20 '22 13:10

Jura Gorohovsky


As has already been mentioned you can do this using the TestCop ReSharper plugin (gallery link).

It ties the class under test to the test fixture by using regular expressions to identify class names and namespaces. You can customise these to fit your needs, but I found there to be a fair amount of trial and error to get this right on existing code.

Once it's all set up you can go back and forth with a keyboard shortcut. It can also do things like create the TestFixture or the class for you.

like image 3
aboy021 Avatar answered Oct 20 '22 13:10

aboy021