Run Unity tests in Rider 2018.1

In our last couple of posts about new Unity features in Rider 2018.1, we’ve seen that updating our Unity editor plugin to be smarter now allows us to control play mode, and bring the Unity console directly into Rider.

In this series:

The intent here is to reduce the amount of time you spend switching between Rider and the Unity editor. If you’re working with code, let’s stick to the code editor. And so we can single step frames from the debugger, and see log entries directly in the code editor, and Rider makes the stack traces clickable to easily navigate to the right places in your code.

We believe that reducing this context switching will help you concentrate on your game logic, rather than your tooling, which we also hope will help improve the quality of your game or visualisation. But we want to do more than hope, so we’ve now integrated Unity’s unit tests into Rider’s test runner, making it easier than ever to test your code.

This allows you to run tests that interact with Unity’s APIs, and which can step single frames, all from within Rider. And of course, you can explore the results of your Unity specific tests, just like you would normal tests – you can filter by result, and click on stack traces to navigate your code.

Rider test tool window

For those not familiar with Unity’s unit tests, there is a constraint that these tests must be run inside the editor application instance. This is because Unity isn’t actually a .NET application, but is a native application, with a Mono based scripting layer, and many of Unity’s APIs are native APIs. If you try and call those APIs in a normal .NET test runner, you’ll see the following rather unfriendly error message:

System.Security.SecurityException : ECall methods must be packaged into a system module

It’s not possible to mock these calls, but instead, you must run the tests inside the editor instance.

Unity editor test runner window

Fortunately, our new Unity editor plugin allows us to do just that, listening to requests from Rider to start running the tests, and then reporting back to Rider, where we can integrate the progress and results seamlessly into the standard test runner.

And Unity support is fully integrated with our unit testing experience. We discover unit tests from the code and highlight test classes and methods right inside the editor. Clicking on the gutter icon, or pressing Alt+Enter will show a menu we can use to run the tests.

NUnit test Alt+Enter menu

You’ll notice that the menu shows Debug as well as Run. Currently, debugging isn’t supported, even though the item is available in the menu. If you select Debug, it will simply run the tests. An easy workaround is to attach the editor via the normal debug button in the top right of the main window, and then run the tests – you’ll be able to set breakpoints and debug as normal. We hope to get debugging enabled again as soon as possible.

Debug toolbar

As if running tests directly from the editor wasn’t reason enough to love this feature, all of Rider’s usual unit testing tools are available, too. You can run all tests in a project or a selection of test classes or even just a single test. You can also group how the tests are shown in the tool window, and filter based on status – passed, failed, skipped.

But best of all, unlike in the Unity editor, where the result output is a block of plain text, Rider will parse the test output, and make stack traces, or even just a class or method name into hyperlinks.

Test runner stack trace navigation

And Rider also includes support for tests marked with the [UnityTest] attribute, not just the traditional nunit [Test] attribute. These are tests with a return type of IEnumerator, where a yield return can skip frames in the editor.

Support for UnityTest attribute

Finally, Rider also includes file templates to quickly create a new test class.

File templates menu

The integrated test runner is supported with Unity 5.6 and above, which is when the test runner was first integrated into the Unity editor. Rider has no special support for Unity tests prior to Unity 5.6, but will run any tests it finds as standard nunit tests.

We’d love to hear your feedback on this and the other new features in Rider 2018.1. Please leave comments here, and you can add feature requests and issues to GitHub or YouTrack. And of course, don’t forget to download Rider 2018.1 and try it out!

Comments below can no longer be edited.

22 Responses to Run Unity tests in Rider 2018.1

  1. Avatar

    George cook says:

    April 19, 2018

    Thanks so much guys. These are such great developments. You guys really need to get a leading unity Dec to present with you at Unite. I’m sure a lot of people have no idea what they are missing and now your product is ready for primetime.

    • Avatar

      Matt Ellis says:

      April 27, 2018

      Thanks! We will be at various Unite events this year.

  2. Avatar

    Trond says:

    April 20, 2018

    I can not get this to work. When i try to run these tests, they just get stuck as “Pending”. What am i doing wrong?

    • Avatar

      Geoff says:

      April 20, 2018

      Same problem. Running Unity 2017.1.2f1.

      • Avatar

        Matt Ellis says:

        April 27, 2018

        Sorry to hear that – is this still an issue? Currently tests require Unity to be running and connected before things will work. We also noticed an issue with the way we installed the plugin, so it might be worth restarting Rider and trying again.

        • Avatar

          quabug says:

          May 3, 2018

          same problem with rider 2018.1 and unity 2018.1
          always pending while unity is running and rider connected to unity

        • Avatar

          hhatinen says:

          May 9, 2018

          Same problem here as well. Debugging works fine so it seems like it connects to unity ok.

        • Avatar

          Felix says:

          May 11, 2018

          Exact same problem here (Rider 2018.1, Unity 2018.1).

          • Avatar

            Matt Ellis says:

            May 15, 2018

            A number of issues with more recent builds of Unity have been fixed in the nightly builds. They should be available soon in Rider 2018.1.1

  3. Avatar

    Geoff says:

    May 3, 2018

    2018.1 EAP is working for me as advertised, but it does not support running with tests annotated as TestCase or TestCaseSource. I’ve heard, but not tried, tests with Values parameters also do not work from Rider. These things do work when running tests from within Unity. Looking forward to having all the kinks worked out, as this is a great feature!

    • Avatar

      Matt Ellis says:

      May 15, 2018

      This has been fixed in recent nightly builds, so should come out in Rider 2018.1.1 (or possibly 2018.1.2)

  4. Avatar

    lesny says:

    May 7, 2018

    Great function! Are there any plans to also have this in ReSharper with Unity plugin??

    • Avatar

      Matt Ellis says:

      September 6, 2018

      Potentially. It would require a fairly significant amount of work to remove Rider specific assumptions from the Unity Editor plugin we install and wire up our two way communication to ReSharper, and not just Rider. There is an [issue on GitHub to track this decision]( for the 2018.3 timeframe.

  5. Avatar

    Garth Smith says:

    September 4, 2018

    This is great! Anything that helps with testing is much appreciated!

    Does anyone know if there is a way to get a code coverage report from a Unity project?

    • Avatar

      Matt Ellis says:

      September 6, 2018

      There isn’t a way to do this right now, unfortunately.

  6. Avatar

    Jerome says:

    October 15, 2018

    Whenever I run Unity tests from within Rider, I always get “Inconclusive: Test not run” in the unit tests window. I’ve also tried creating a new test using the Rider “Play mode test” template, and those never run either.

    When I initiate the test, you can see Unity briefly act like it’s switching scenes like normal, but then it quickly stops.

    The bottom right corner of Rider shows that I’m connected to Unity.

    JetBrains Rider 2018.2.3
    Build #RD-182.4231.496, built on September 13, 2018
    JRE: 1.8.0_152-release-1248-b8 amd64
    JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
    Windows 10 10.0
    Unity 2017.3.1f1

    • Avatar

      Matt Ellis says:

      October 18, 2018

      Unfortunately, play mode tests aren’t supported, only edit mode tests. We’re currently working on an implementation and hope to have it ready for a future release.

      • Avatar

        Dan Jacobsen says:

        January 30, 2019

        Really looking forward to playmode test support, thanks for adding these features!

  7. Avatar

    Lak says:

    July 5, 2019

    Does rider provide code coverage analysis for Unit tests in Unity?

    • Avatar

      Matt Ellis says:

      July 17, 2019

      Not yet, but it is something we want to provide in a future release.

  8. Avatar

    Alejandro Radisic says:

    July 29, 2019

    Hello, I’m trying to run the tests on EditMode, but none of them are actually detected unless I change the tag to [Test] instead of [UnityTest].

    Also, if I change them to [Test] and run them, I get the following error: “Inconclusive: Test not run”

    Any workarround to this? Can’t figure a way to get it working and seems like a great feature

  9. Avatar

    Max Palmer says:

    January 13, 2020

    Has there been any update on plans to get this working with ReSharper?

Discover more