Search Issue Tracker
By Design
By Design in 1.14.X
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
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
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
- VFX Graph Debug Info overlaps the "Initialize" block debug info by default
Resolution Note:
IWhen 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;
}
}
}
Resolution Note (1.14.X):
IWhen 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;
}
}
}