Understudy is a mocking library for the Unity Test Framework. A test replaces any member the code under test reaches with a stub or a fake, or watches it with a spy: Time.deltaTime, Random.Range, Physics.Raycast, Camera.main, your own singletons, constructors, fields and events. The code under test needs no interfaces or wrappers for it, because Understudy rewrites the code in the Editor so that each test decides how a member behaves. For what a double can't reach, such as code Burst compiles or the engine's own state, refer to What a double doesn't reach.

Understudy also detects leaks: it warns when a test reaches a random value, a clock or global state that the test didn't declare, which makes the test depend on things outside it.

This manual assumes you can write and run tests with the Unity Test Framework, which is based on NUnit. If you can't, start with Write your first test, which writes a first test step by step, or refer to Unity Test Framework in the Unity Manual. If you already use NSubstitute or Moq, refer to Compared with other mocking libraries.

User Manual sections

SectionDescription
Get startedInstall Understudy, set up a test assembly, write a first test, and learn what spies, stubs, fakes and leaks are.
Write testsTest common Unity code, select members, stub them, check what the code under test did, fake fields, properties and events, run members for real, and control how long a double lasts.
Leaks and weavingCatch tests that depend on real global state, and understand how Understudy rewrites the code under test in the Editor.
ReferenceSettings, code analysis messages, troubleshooting and terms.

Contact

For questions and bug reports, use the contact form or email justetools@gmail.com, with what you expected and what happened. I answer within one business day.

Understudy is distributed under the Unity Asset Store EULA.

Additional resources