Search Issue Tracker

In Progress

Votes

0

Found in [Package]

1.14.0

Issue ID

ISXB-1509

Regression

No

ArgumentOutOfRangeException thrown when defining device in [OneTimeSetUp] and using [OneTimeTearDown] to remove it

Package: Input System

-

How to reproduce:

1. Open the project "IN-97542_Keyboard"
2. Open Windows → General → Test Runner
3. Click on "PlayMode"
4. Double click the "Ch 18 - Unity testing"
5. Observe the Console

Expected result: Fails gracefully, with a more defined error message
Actual result: ArgumentOutOfRangeException thrown

Reproducible with: 1.5.0 (2023.2.0a1) 1.14.0 (2023.2.0a1, 2022.3.61f1, 6000.0.46f1, 6000.1.0b14, 6000.2.0a8)

Reproducible on: Windows 11
Not reproducible on: No other environments tested

  1. Resolution Note:

    When using the InputTestFixture you need to use [SetUp] and [TearDown]. [OneTimeSetup] & [OneTimeTeardown] have different timing and won't work well with the InputTestFixture's lifecycle.
    This is due to how the InputTestFixture mocks user input data and it's load / restore mechanism. Old data was restored in your repo project's case causing issues.

    We have added documentation around this for an upcoming release to avoid confusion.

    Here is also a minimal working test for this case that had the same scene setup used in the repo project. Copying this Setup / Teardown code should fix the issue for you.

    Swapping between [OneTimeSetup] & [OneTimeTearDown] vs [SetUp] & [TearDown] with the same code should also reproduce / fix the error without the need for the workaround you provided also.

    using System.Collections;
    using NUnit.Framework;
    using UnityEditor.SceneManagement;
    using UnityEngine.InputSystem;
    using UnityEngine.SceneManagement;
    using UnityEngine.TestTools;

    namespace Tests.InputSystem
    {
    public class SceneLoadingTests : InputTestFixture
    {
    private const string TestScenePath = "Assets/Tests/InputSystem/Assets/AutoSwitchBoolTestScene.unity";
    private Scene m_Scene;

    [SetUp]
    public void SetUpTest()
    {
    m_Scene = EditorSceneManager.LoadSceneInPlayMode(TestScenePath, new LoadSceneParameters(LoadSceneMode.Additive));
    }

    [TearDown]
    public void TearDown()
    {
    SceneManager.UnloadScene(m_Scene);
    }

    [UnityTest]
    [Category("SceneLoading")]
    public IEnumerator Users_CanLoadASceneWithPlayerInputAutoSwitchFlagSetToTrue_InTestsWithInputTestFixture()
    {
    yield return null;
    }
    }
    }

Add comment

Log in to post comment