Search Unity

Question [Testing] How to perform the same action twice using InputTestFixture ?

Discussion in 'Input System' started by bali33, Oct 11, 2022.

  1. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hello,

    I'm trying to write test using InputTestFixture in order to control a character. This test only makes the character jumps but it can't make it jump twice: I can't "Press" the same button twice or I can't trigger the same action twice. I don't know.

    I'm pretty my understanding about InputTestFixture is not good enough and I'm surely doing something wrong.

    Here the code :

    Code (CSharp):
    1. [UnityTest]
    2.     public IEnumerator CanJumpMultipleTimes()
    3.     {
    4.         var gamepad = InputSystem.AddDevice<Gamepad>();
    5.        
    6.         var jumpAction = new InputAction("Jump", binding: "<Gamepad>/buttonSouth");
    7.         jumpAction.Enable();
    8.        
    9.         yield return new WaitForSeconds(5f);
    10.        
    11.         //Player jump
    12.         Press(gamepad.buttonSouth);
    13.        
    14.         //PressAndRelease does not make the player jump
    15.         //PressAndRelease(gamepad.buttonSouth);
    16.        
    17.         yield return new WaitForSeconds(3f);
    18.        
    19.         //This time player does NOT jump
    20.         Press(gamepad.buttonSouth);
    21.        
    22.         yield return new WaitForSeconds(5f);
    23.     }