Library for mocking the Input Manager (Legacy, UnityEngine.Input).
Required Unity 2019 LTS or later.
The UnityEngine.Input class provides static methods.
You can inject test stubs into your tests by replacing Input with the IInput interface.
Usage:
1. Insert the code below into your product code to replace UnityEngine.Input with a TestHelper.Input.InputWrapper instance
#if UNITY_INCLUDE_TESTS
internal IInput Input { private get; set; } = new InputWrapper();
#endifTip
InputWrapper also works at runtime, but you can remove the TestHelper.Input assembly from the build using the #if UNITY_INCLUDE_TESTS directive.
public class StubInput : InputWrapper
{
public KeyCode[] PushedKeys { get; set; } = Array.Empty<KeyCode>();
public override bool GetKey(KeyCode key)
{
return PushedKeys.Contains(key);
}
}[UnityTest]
public IEnumerator PushW_MoveForward()
{
var sut = new GameObject().AddComponent<SUT>();
var stub = new StubInput();
sut.Input = stub; // Inject test stub
stub.PushedKeys = new[] { KeyCode.W }; // Push W key
yield return new WaitForSeconds(0.5f);
stub.PushedKeys = Array.Empty<KeyCode>(); // Release key
var actual = sut.transform.position;
Assert.That(actual, Is.EqualTo(new Vector3(0f, 0f, 4f))
.Using(new Vector3EqualityComparer(0.3f)));
}- Open the Project Settings window (Editor > Project Settings) and select Package Manager tab (figure 1.)
- Click + button under the Scoped Registries and enter the following settings:
- Name:
package.openupm.com - URL:
https://package.openupm.com - Scope(s):
com.nowsprinting
- Name:
- Open the Package Manager window (Window > Package Manager) and select My Registries tab (figure 2.)
- Select Input Test Helper and click the Install button
Figure 1. Scoped Registries setting in Project Settings window
Figure 2. My Registries in Package Manager window
- Open your product and test assembly definition file (.asmdef) in Inspector window
- Add TestHelper.Input into Assembly Definition References
MIT License
Open an issue or create a pull request.
Be grateful if you could label the PR as enhancement, bug, chore, and documentation.
See PR Labeler settings for automatically labeling from the branch name.
Add this repository as a submodule to the Packages/ directory in your project.
Run the command below:
git submodule add [email protected]:nowsprinting/test-helper.input.git Packages/com.nowsprinting.test-helper.inputGenerate a temporary project and run tests on each Unity version from the command line.
make create_project
UNITY_VERSION=2019.4.40f1 make -k testWarning
You must select "Input Manager (Old)" or "Both" in the Project Settings > Player > Active Input Handling for running tests.
The release process is as follows:
- Run Actions > Create release pull request > Run workflow
- Merge created pull request
Then, will do the release process automatically by Release workflow. After tagging, OpenUPM retrieves the tag and updates it.
Caution
Do NOT manually operation the following operations:
- Create a release tag
- Publish draft releases
Caution
You must modify the package name to publish a forked package.
Tip
If you want to specify the version number to be released, change the version number of the draft release before running the "Create release pull request" workflow.



