Diagnostic codes

Understudy checks the code of every test assembly, in your code editor as you type and in the Console window when Unity compiles. Each message has a code: UST00xx codes are errors, UST01xx warnings and UST02xx hints. Where a fix exists, your code editor offers it as a quick action.

Your code editor shows these messages when it opens the project files Unity generates, as Visual Studio, Rider and Visual Studio Code do with Unity's Visual Studio Editor or JetBrains Rider Editor package.

Errors

CodeMessage and fix
UST0002A selection names a single member
A selection is one method, constructor, field, property, element written with [], event or user-defined operator. A built-in operator, such as count + 1, isn't a member, and a const is copied into the code, so no access to it remains. A local variable, a method group, a block body, and a member that returns by reference, or takes or returns an open generic type, a pointer or a ref struct such as Span<T>, can't be selected either.
UST0005Arg.Ignored names an event in an Event selection
An Event selection is a += or -= of Arg.Ignored on an event, and Arg.Ignored means nothing anywhere else.
UST0006A selection's lambda parameter stands for the instance
A lambda parameter makes the selection cover every instance. It can't stand for an argument: use Arg.Any or Arg.That.
UST0007Arg.Ignored cannot fit this event's delegate
For a delegate with a return value and no parameters, write the return type: Arg.Ignored<bool>. Fix: Write Arg.Ignored<T>. When two events in an assembly have the same parameters and different return types, write every type argument.
UST0008Raise's arguments do not fit the event
The arguments of Raise and EachRaise must fit the event's delegate.
UST0009An Arg matcher outside a selection
A matcher only means something inside a selection's lambda. Anywhere else it does nothing, and it throws if it runs.
UST0011An Arg matcher stands for a whole argument
A matcher inside another expression, such as new Ray(Arg.Any<Vector3>(), dir), or in place of the instance, matches nothing. Match the whole argument, and use a lambda parameter for every instance.
UST0012The entry point names the kind of the member selected
Method takes a method, an operator or a conversion; Constructor a new; Field a field; Property a property; Indexer an element written with []; Event a += or -= of Arg.Ignored. A field selected with Property, or a property with Field, is the most common case. Fix: Use followed by the entry point the message names, such as Use Property.
UST0013A selection names a whole member
A field of a struct, such as player.stats.health, is part of the member holding the struct: select player.stats. A field of the copy a property returns, such as transform.position.x, belongs to no code: select the property.
UST0014A selection names a member as it is read
Select () => player.health, not an assignment to it: the member's writes belong to the same double. A stub decides them with Do, a fake stores them, a spy records them in Writes.
UST0015An answer's parameters do not fit the member
An answer takes no parameters, or what each access passes: a call's arguments, an element's indices, then for Do on a field, a property or an element the value written. An answer set on a table with EachReturns or EachDo can also take the instance first.

Errors from the compilation step

Understudy checks each selection again when Unity compiles your tests, so a mistake the code editor didn't show, such as one in a file compiled outside it, still fails in the Console window with its UST code. Fake.Method, Stub.Event and the other entry points a role doesn't have don't exist, so the C# compiler reports CS0117. Your code editor offers a fix that switches to a role that has the entry point, such as Use Stub.

The compilation step also reports two errors of its own:

  • Understudy: the definition of ... is missing, so no selection can name it.: the compilation step can't load the assembly that declares the member. Restart the Editor. If the error persists, report the full message through the contact form.
  • Understudy: the type of this array is unknown here: select the array through a field, a property or a local of array type.

Warnings

CodeMessage and fix
UST0101A constructor stub with no Returns
A stub with nothing declared returns the C# default, so new returns null, which code never expects. Give it a Returns.

Hints

CodeMessage and fix
UST0201A method call inside a selection
A selection's expressions run at every access it is checked against. Hold the method's result in a local.
UST0202An unused instance parameter
Give a table's answer the instance as its first parameter only when it uses it. An answer with a single parameter of the instance's type receives the call's argument, not the instance.
UST0203A broad declaration after a narrower one
The last stub, fake or Real declared decides, so a broad one declared after a narrow one hides it. Declare the broad one first.
UST0204A test reads a member it replaces
A stub or fake decides the accesses the code under test makes, and the test's own read reaches the real member. Read the fake's Value, or check what the code under test did.

Other fixes

Returns(null) and initial: null don't compile (CS0121), since null fits both a value and a computed value. Your code editor offers Write Returns((T)null) or Write initial: (T)null.

An answer's parameters need their types, since C# can't infer them from the selection. Returns(x => x + 1) fails with CS1660, and Do(x => { }) on a void call with CS1593. Your code editor offers Write the parameter types.

Suppress a diagnostic

Warnings and hints can be suppressed like any C# diagnostic, with #pragma warning disable UST0201 around the code, or with an .editorconfig rule. Errors mark code that can't work. Suppressing one only hides it: the compilation step still fails on a selection error, and code with any other error throws when it runs.

Additional resources