ReSharper Platform SDK
 
Because ReSharper Platform SDK undefined is still in development, this documentation may not be entirely accurate and is subject to change.

.NET Core Tests

Last modified: 04 July 2023

ReSharper's support for running tests for .NET Core projects is different to how it supports desktop CLR projects. Instead of using its own JetBrains.ReSharper.TaskRunner.CLR4.exe external process to run tests, it uses the .NET Core SDK dotnet test command line tool. The dotnet test command runs an external process from a NuGet package referenced in the project file (e.g. dotnet-test-xunit and dotnet-test-xunit.exe) which in turn runs your tests. But it can also be invoked in "design mode", which allows a host to connect to the running process and issue commands and receive messages. An IDE can use this protocol to discover tests and run subsets of tests, getting feedback in real time.

ReSharper uses this protocol to run .NET Core tests. The workflow is as follows:

  • Discover tests in-editor. The existing providers analyse source code in the same way they do for desktop CLR projects. This allows ReSharper to show the usual rich editing features - such as icons in the editor gutter, Alt+Enter actions for run and debug, and identifying methods and classes as tests in Find Usages.

  • Discover tests at build time. When the project is built and the output assembly is changed, invoke dotnet test in design time mode to run test discovery. The list of tests discovered are treated as "the truth".

  • Map dotnet test IDs to ReSharper elements. When a test is discovered, it is reported with an ID that is relevant only to the test runner from the NuGet package. A ReSharper test provider must map between this ID and a ReSharper unit test element.

  • Run or debug tests. ReSharper currently only supports run and debug actions for .NET Core tests. When run or debug is invoked, dotnet test is invoked in design time mode, and the currently selected tests are run, by using the element map to produce a list of dotnet test IDs. Messages are received from the test process, and the ID to element map is again used to update the test status of the elements in the ReSharper UI.

Furthermore, a .NET Core project can support targeting multiple frameworks, such as .NET Core and/or the .NET Framework. ReSharper will run discovery for each target framework in a project, and create an IUnitTestElement for each test in each target framework. (ReSharper must create multiple test elements as each target framework build might have different #if defines that comment out tests.)

Adding support to an existing test provider for ReSharper is straightforward. ReSharper does all of the work of starting test discovery, running the tests and reporting test progress. A test provider only needs to map between dotnet test IDs and IUnitTestElement instances, which it can do by implementing a solution component that derives from DotNetTestArtefactsExplorer.