How to simulate VR input in automatic testing?

How do you simulate VR input from code in automatic tests using Unity Test Framework?

I need to automate testing of the VR player grabbing things, dropping them, etc…

Looked through a lot of docs and tutorials to try to find a path to do this, found nothing. Tried a lot of things myself, nothing works.

I’m using the new Unity Input Package and all the standard Unity VR packages/plugins etc… along with XR Interaction Toolkit

Hey @edwon ,
If you are looking for some examples of how to do some of this type of test automation, XRI actually has a lot of automated testing you can use as a reference. You will need to add it to the testables area of your project manifest like so:

{
  "dependencies": {
     ... existing dependencies ...
  },
  "testables": [
    "com.unity.inputsystem",
    "com.unity.xr.interaction.toolkit"
  ]
}

We have an internal dependency on the Input System for our test fixture, which is why you will need both. Once you have that inserted into your manifest, you’ll want to open up the Test Runner (Window > General > TestRunner) window to see the list of tests:


The actual C# scripts responsible for these tests can be accessed inside the project by expanding the Packages area in the Project window and navigating to XR Interaction Toolkit > Tests > Runtime:
8478110--1126985--upload_2022-9-29_13-57-52.png
Hopefully this helps you get started in building your own tests. Feel free to reach out if you have more questions.

Ok thanks for the instruction! I saw this mesage and it was like Christmas.

So digging through the test code, I found this:

var controllerRecorder = TestUtilities.CreateControllerRecorder(controller, (recording) =>
{
    recording.AddRecordingFrameNonAlloc(new XRControllerState(0.0f, Vector3.zero, Quaternion.identity, InputTrackingState.All, true, false, false));
    recording.AddRecordingFrameNonAlloc(new XRControllerState(float.MaxValue, Vector3.zero, Quaternion.identity, InputTrackingState.All,
                    true, false, false));
});
controllerRecorder.isPlaying = true;

So I’m guessing this is how you do it? basically just add an XRControllerRecorder and then add some frames and start it playing

still haven’t found how to move the head around though

Hey @edwon
You could likely just move the XR Origin in a similar manner, since that would bring the child objects with it. Otherwise you can find and move the main camera in whatever test setup you are using.

The main issue here is input, such as buttons on the hand controller, and also the hand positions, I already tried moving the camera and origin and hands via direct transform manipulation.