Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Help Wanted Is there a way to make time pass in a test?

Discussion in 'Testing & Automation' started by AcademyOfFetishes, Apr 21, 2019.

  1. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    215
    Although this test takes ~3 seconds to run, it still fails:

    Code (CSharp):
    1.     [UnityTest]
    2.     public IEnumerator time_passes()
    3.     {
    4.         var originalTime = Time.time;
    5.         for (int i = 0; i < 500; i++)
    6.         {
    7.             yield return null;
    8.         }
    9.         Assert.Greater(Time.time, originalTime);
    10.     }
    This is the output:

    Code (CSharp):
    1. Expected: greater than 0.283833772f
    2.   But was:  0.283833772f
    Is there a way in an editor test to make time pass?
     
  2. Warnecke

    Warnecke

    Unity Technologies

    Joined:
    Nov 28, 2017
    Posts:
    26
    liortal likes this.
  3. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    215
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,221
    What are you trying to test exactly? maybe asserting against Time.time isn't the best solution for you.