ReSharper 2024.3 Help

Navigate between tests and tested code

ReSharper helps you navigate between unit tests and tested code. When your caret is at the name of a class or anywhere within its declaration, you can press Control+T F to navigate to related tests and vice versa, by pressing this shortcut on a test, you will jump to the tested class.

This navigation is also available in the Navigate To Control+Shift+G menu: select Test Subject if you navigate from a unit test, and Related Tests when you navigate from a tested class.

For navigating to and from unit tests, ReSharper establishes links between test classes and the corresponding tested classes. There are several approaches to linking tests and tested classes: all of them are used by default, and you can configure them on the Tools | Unit Testing | Test Linker page of ReSharper options Alt+R, O:

Use affix search

ReSharper links test classes whose names start or end with the specified affixes to the corresponding classes in tested code. Clear this checkbox to ignore test class names and use other heuristics for navigation.

Use attribute-based search

ReSharper links test classes annotated with a specific attribute to the corresponding classes in tested code.

ReSharper always takes into account the [TestSubject] attribute from JetBrains.Annotations. For example, if you navigate from a class named SampleClass, tests annotated with [TestSubject(typeof(SampleClass))] will be suggested as navigation destinations.

If you annotate tests with another attribute to link them to tested classes, specify the fully-qualified name of this attribute to take it into account in addition to [TestSubject]. Note that you can only specify one attribute per solution.

Clear this checkbox to ignore attributes and use other heuristics for navigation.

Use generic argument search

ReSharper links test classes with tested classes when the base test class has a generic parameter that represents the tested class, and this generic parameter is annotated with a specifc attribute.

Consider the following example:

[TestFixture] public abstract class TestsFor<[MeansTestSubject] T> { private AutoMock myMock; public T Component => myMock.Create<T>(); } public class TestsForSampleClass : TestsFor<SampleClass> { [Test] public void TestSample() { Component.DoSomething(); } }

In this example, generic parameter T is annotated with the [MeansTestSubject] attribute from JetBrains.Annotations. This attribute is always taken into account in such scenarios. If you use another attribute for these purposes, specify its fully-qualified name to take it into account in addition to [MeansTestSubject]. Note that you can only specify one attribute per solution.

Clear this checkbox to ignore generic arguments and use other heuristics for navigation.

This feature is supported in the following languages and technologies:

Language: C#

Language: VB.NET

Language: C++

Language: HTML

Language: ASP.NET

Language: Razor

Language: JavaScript

Language: TypeScript

Language: CSS

Language: XML

Language: XAML

Language: Resx

Language: Build Scripts

Language: Protobuf

Language: JSON

Feature is available in C#

Feature is available in Visual Basic

Feature is not available in C++

Feature is not available in HTML

Feature is not available in ASP.NET

Feature is not available in Razor

Feature is not available in JavaScript

Feature is not available in TypeScript

Feature is not available in CSS

Feature is not available in XML

Feature is not available in XAML

Feature is not available in Resource files

Feature is not available in build script files

Feature is not available in Protobuf

Feature is not available in JSON

The instructions and examples given here address the use of the feature in C#. For more information about other languages, refer to corresponding topics in the ReSharper by language section.

Last modified: 11 February 2024