I wrote a simple test case using Unity Test Tools, and I’d like to use NUnit’s ‘Timeout’ attribute to handle timeout declaratively.
I tried the following code, but it seems that even though timeout itself works correctly (meaning failing the test), it doesn’t stop the coroutine which causes the Unity TestRunner to hang indefinitely:
[UnityTest, Timeout(3), Description("It should move towards the target destination.")]
public IEnumerator ShouldMoveTowardsTargetDestination(
[TestRange(0, 360, 45)] float heading,
[Values(1, 10)] float distance)
{
Debug.LogFormat("Using data: heading={0}deg., distance={1}m.", heading, distance);
var transform = Navigator.Transform;
var destination = Quaternion.AngleAxis(heading, transform.up) * transform.forward * distance;
Navigator.Destination = destination;
while (transform.position != destination)
{
Navigator.LateTick();
yield return null;
}
Expect(
transform.position,
Is.EqualTo(destination),
"Navigator has failed to reach the destination.");
}
Is there any way to use *Timeout* attribute, rather than programatically checking elapsed time? Or is it possible to exit the while loop once the surrounding test fails?
Thanks!