Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

InputTestFixture.Press only working in Setup() not in test functions.

Discussion in 'Input System' started by Ollie_Palmer, Jul 25, 2020.

  1. Ollie_Palmer

    Ollie_Palmer

    Joined:
    Jun 17, 2019
    Posts:
    4
    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:

    Code (CSharp):
    1.  
    2. public class SomeTestScript: InputTestFixture
    3.     {
    4.         Gamepad gamepad1;
    5.  
    6.        [UnitySetUp]
    7.         public IEnumerator SetUp() {
    8.             base.Setup();
    9.  
    10.             TestHelpers.LoadScene("StartScene");  
    11.             yield return new WaitForSceneLoaded("StartScene");
    12.             yield return new WaitForEndOfFrame(); //Awake
    13.             yield return new WaitForEndOfFrame(); //Start
    14.             gamepad1 = InputSystem.AddDevice<Gamepad>();
    15.      }
    16.  
    17.  
    Then I have a test that navigates a menu, essentially so that a new scene loads.

    Code (CSharp):
    1.    [UnityTest]
    2.         public IEnumerator loadGameScene() {
    3.  
    4.             yield return new WaitForSeconds(0.3f);
    5.             Press(gamepad1.dpad.down);
    6.             Release(gamepad1.dpad.down);
    7.             yield return new WaitForSeconds(0.3f);
    8.             Press(gamepad1.dpad.up);
    9.             Release(gamepad1.dpad.up);
    10.             yield return new WaitForSeconds(0.3f);
    11.             Press(gamepad1.buttonSouth);
    12.             Release(gamepad1.buttonSouth);
    13.  
    14.             yield return new WaitForSceneLoaded(nameOfNewSceneToLoad);
    15.             //Some assertion that checks new scene has loaded
    16.          }


    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:
    Code (CSharp):
    1.  
    2. InputUser.onUnpairedDeviceUsed += (control, eventPtr) => { onUnpairedDeviceUsed(control, eventPtr); };
    3.  

    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!


     
  2. Ollie_Palmer

    Ollie_Palmer

    Joined:
    Jun 17, 2019
    Posts:
    4
    Does anyone have a fix for testing Inputs in PlayMode?

    I just want to mock an input sequence.
     
  3. Ollie_Palmer

    Ollie_Palmer

    Joined:
    Jun 17, 2019
    Posts:
    4
  4. spajus

    spajus

    Joined:
    Jun 10, 2015
    Posts:
    13
    You're right about this. Try getting rid of that onUnpairedDeviceUsed callback and see how it works. Your test code looks like it should work, very similar to mine, nothing special. Maybe also try upgrading input system + test framework via package manager, if the versions are not up to date.
     
unityunity