Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

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.     }