Calling IEnumerator methods in a UnityTest in PlayTest fixtures

Hello,

I’m currently attempting to make modular helper/auxillary methods for my PlayTests (to avoid duplicate code).

public IEnumerator navigateToGameScene()
{
    gamepad1 = InputSystem.AddDevice<Gamepad>();
    yield return new WaitForSeconds(0.3f);
    Press(gamepad1.dpad.up);
    Release(gamepad1.dpad.up);
    yield return new WaitForSeconds(0.3f);
    Press(gamepad1.dpad.up);
    Release(gamepad1.dpad.up);
    yield return new WaitForSeconds(0.3f);
    Press(gamepad1.buttonSouth);
    Release(gamepad1.buttonSouth);
}

However, some of these may require waiting for frames or some amount of seconds.
How do I call these helper/auxillary methods that aren’t tagged with [UnityTest]?

Using StartCoroutine(navigateToGameScene) doesn’t work.
Ideally this is what I’d want to do:

[UnityTest]
public IEnumerator somePlayTest()
{
        //Do some test specific setup
        //Call auxillary method e.g.
        yield new StartCouroutine(navigateToGameScene);
        //Some more code
        //Assertion
}

Thanks in advance.

1 Like

You should be able to do just

yield return navigateToGameScene();

However, you’ll probably run into this Unity bug sooner or later.

If you are interested in reusability of test methods like this, and working around that bug, you might want to take a look at Responsible :wink:

1 Like

That worked - thanks a lot for this and the heads up on that bug. :slight_smile:

Responsible looks neat, thanks for the recommendation!