Faster Unity TestRunner


Did you know that you can speed up Unity test runs by about 30%?

Yes? Then you must have already read this article. 🙂

If no, then read on …

What makes Tests faster?

Unity has a little known setting called Interaction Mode that controls the frequency of all Editor processing:

The Default setting locks the Editor to 60 Hz (fps). The Monitor Refresh Rate puts the refresh rate in sync with the monitor – in my case that would be 120 Hz (8 ms).

Curiously, this also affects running tests!

If you have enough tests that a full test run takes at least a couple seconds you can try this yourself:

  • Stop the time it takes to perform a full test run.
  • Set Interaction Mode to No Throttling.
  • Stop the time it takes to perform a full test run again.

You should notice that tests run measurably faster, perhaps even noticably. Cases vary, but in mine I had several hundred tests that used to take 14s to complete. Without throttling, they complete in about 10s.

Test-Only No-Throttling

Now, the thing with No Throttling is: it consumes a lot of energy unnecessarily and it will spin up the fans. Wouldn’t it be nice to have No Throttling set ONLY during tests?

You can do it with this FasterTests script.

It uses the TestRunnerAPI callbacks RunStarted and RunFinished to change the EditorPrefs values that control Interaction Mode.

Now every time you run a test, it runs as fast as it possibly could! And after the tests are complete, the Interaction Mode is reset back to its original setting.

Enjoy faster tests, just like that! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

WordPress Cookie Notice by Real Cookie Banner