How-To's

Unit Testing Improvements in Rider 2019.1

In the latest Rider 2019.1 Early Access Preview (EAP) builds, we made a number of improvements to unit testing – in the overall performance as well as the UI/UX experience.

For example, it’s now possible to run tests from Find Usages, making it easy to find tests that use a certain type or method we want to verify. Rider can now track running tests, automatically showing details for the test that is running.

Next to these, a number of UI/UX improvements were made. Additional grouping rules have been added, including grouping by namespace or by category. The test tree and output pane are automatically split horizontally/vertically based on available space. We can now also customize the testing toolbar and hide empty test filters. More than enough to have a closer look!

DOWNLOAD Rider 2019.1 EAP

Performance!

In earlier releases, the test tree was kept in memory in both the front-end and Rider’s back-end (read more on Rider’s architecture). This meant that in solutions with a large number of tests, there was quite some impact on performance and memory usage.

The test runner’s performance and memory usage have greatly improved in this release! The test tree is now fully asynchronous and only synchronizes the view model for expanded parts of the test explorer and test sessions. This refactoring makes working with tests faster and speeds up solution loading.

Run/debug tests from Find Usages

Want to check if a given class or method is used in test code directly? We can do that with Find Usages (Shift+F12). Even better, for test methods that are found we can now immediately run the test by using the context menu (or keyboard shortcut).

Run test from Find Usages tool window

Tip: Find Usages will only find tests when they reference our class or method directly. Not to worry! We can always use unit test coverage and dotCover to get more accurate navigation between code under test and the tests that use it.

From the test tool window, we can now also Navigate to… (Alt+`) a test class or test method’s implementation, Find Usages of a test, and perform other actions.

Navigate To / Find Usages from unit test tool window

Track running tests

In the unit tests tool window, we’ve added a new option called Track Running Test. When enabled, Rider automatically selects the test that is currently running in the test tree so that we can follow its output while executing.

Track running test

Note that while running tests, we now also show a progress bar which displays the number of tests passed, failed or ignored, helping us keep track of how far along our test run is.

Improvements to UI/UX and performance

Rider 2019.1 comes with several UI/UX improvements for the test runner. Test frameworks like MSTest, NUnit, and xUnit allow you to group tests by category:

// MSTest:
[TestCategory("Sample category name")]
public void SomeTest() { }

// NUnit:
[TestCategory("Sample category name")]
public void SomeTest() { }

// xUnit:
[Trait("Category", "Sample category name")]
public void SomeTest() { }

The test runner in Rider now lets us group by namespace and test categories as well:

Group tests by category and more

The splitter between the test tree and test output now automatically moves from horizontal to vertical and back, based on the available screen real estate. Note that from the toolbar, we can lock it in the horizontal or vertical position.

Automatic smart splitter

The toolbar can now be customized from Rider’s settings (under Appearance & Behavior | Menus and Toolbars, find the Unit Test Tool Window toolbars).

Customize the test runner toolbars

In the toolbar, test filters are automatically displayed or hidden based on whether there are tests that match a filter or not. So if no tests failed, that filter will not be shown. This behavior can be toggled from the toolbar (Hide Empty Test Filters).

When a test fails, stack traces in the result pane can be navigated using the Ctrl+Alt+Up/Down keyboard shortcuts.

Download Rider 2019.1 EAP and give it a try! We’d love to hear your feedback.

image description