Time.time and Unittesting can't work together?

Hi,

If a unit test is run from Monodevelop that relies on Time.time, this exception occurs:

System.MissingMethodException : Cannot find the requested method

E.g. this code:

[TestFixture]
public class Tests
{
    [Test]
    public void TestUnityTime()
    {
        var result = new Foo().UnityTime();
        Assert.Greater(result, 0);
    }
}

public class Foo 
{
    public float UnityTime()
    {
        return Time.time;
    }
}

To be fair it does make sense that Unity’s time doesn’t run during a unit test. But, is there a way we can test time-using code in Unittests then? Can I manually start the timer? Have you found a way to mock it? How can one unit test any code that uses Time.time?

Thanks

One way I’m trying now is to switch to this amazing alternative implementation of Time.time:

public static class Time2
{
    public static float time
    {
        get
        { 
            float time;
            try
            {
                time = Time.time;
                
            } catch (System.MissingMethodException)
            {
                time = 0.0f;
            }
            return time;
        }
    }
}

I guess that’ll work.