Write tests
Test common Unity code, select members, stub them, check what the code under test did, fake fields, properties and events, and run members for real.
A test with Understudy is an ordinary NUnit test: it declares spies, stubs and fakes, runs the code under test, and checks the result with NUnit constraints. For ready examples of what game code reaches most often, start with Test common Unity code; each of its examples links to the page that covers the feature in full.
Topics
| Topic | Description |
|---|---|
| Test common Unity code | Components, time, randomness, singletons, input, raycasts, events, coroutines, async code, logs, saves and scene loads. |
| Select a member | Name the member a spy, stub or fake covers, for one instance or every instance, with argument matchers. |
| Stub members | Replace methods, constructors, fields, properties and indexers with the answers your test sets. |
| Check what the code under test did | Spy on a member, and check what any spy, stub or fake recorded with NUnit constraints. |
| Fake fields and properties | Give a field or property a stored value the code under test reads and writes instead of the real one. |
| Fake events | Replace an event, raise it from the test, and check its handlers. |
| Run members for real | Declare that a member runs for real on purpose, over a stub or fake or for leak detection. |
| Spy on caught exceptions | Check which exceptions the code under test catches, and what it does with them. |
| Lifetime | When a spy, stub or fake starts and ends, and how each test starts it fresh. |
| Share doubles between tests | Group spies, stubs and fakes in a class of your own, and reuse it across tests and fixtures. |