So I am currently testing my game and wanted to mock input (e.g. to navigate the start menu and load a new game).
Here is my Setup code:
public class SomeTestScript: InputTestFixture
{
Gamepad gamepad1;
[UnitySetUp]
public IEnumerator SetUp() {
base.Setup();
TestHelpers.LoadScene("StartScene");
yield return new WaitForSceneLoaded("StartScene");
yield return new WaitForEndOfFrame(); //Awake
yield return new WaitForEndOfFrame(); //Start
gamepad1 = InputSystem.AddDevice<Gamepad>();
}
Then I have a test that navigates a menu, essentially so that a new scene loads.
[UnityTest]
public IEnumerator loadGameScene() {
yield return new WaitForSeconds(0.3f);
Press(gamepad1.dpad.down);
Release(gamepad1.dpad.down);
yield return new WaitForSeconds(0.3f);
Press(gamepad1.dpad.up);
Release(gamepad1.dpad.up);
yield return new WaitForSeconds(0.3f);
Press(gamepad1.buttonSouth);
Release(gamepad1.buttonSouth);
yield return new WaitForSceneLoaded(nameOfNewSceneToLoad);
//Some assertion that checks new scene has loaded
}
However, the Press and Release calls in loadGameScene() have no effect. But if I move them to the setup function they work fine?
I am manually handling InputUsers and pairing them with devices based on calls via this:
InputUser.onUnpairedDeviceUsed += (control, eventPtr) => { onUnpairedDeviceUsed(control, eventPtr); };
According to the documentation, these calls may stop working in test fixtures? :
“InputTestFixture will sever the tie of the input system to the Unity runtime. This means that while the test fixture is active, the input system will not receive input and device discovery or removal notifications from platform code.”
Thanks a lot in advance for any help!