public void GetPreciseElapsedTime() { var instrumentation = new Instrumentation(); instrumentation.Start(); Thread.Sleep(750); var elapsed = instrumentation.GetPreciseElapsedTime(); Assert.IsTrue(0.75 <= elapsed && elapsed <= 0.78); }
public void GetPreciseElapsedTime() { var instrumentation = new Instrumentation(); instrumentation.Start(); Thread.Sleep(750); var elapsed = instrumentation.GetPreciseElapsedTime(); //Assert.IsTrue(elapsed >= 0.75 && elapsed < 0.751); //fails because using reflection (in GetPreciseElapsedTime) takes time. Assert.IsTrue(elapsed >= 0.75 && elapsed < 0.78);//passes because we broadened the range. //Could have fixed by taking the ending time before using reflection istead, but this example shows the limitations of reflection. }
public void GetPreciseElapseTimeTest() { //-- Arrange Instrumentation instrumentation = new Instrumentation(); //-- Act instrumentation.Start(); Thread.Sleep(750); double elapsedTime = instrumentation.GetPreciseElapsedTime(); Debug.Write(elapsedTime); //-- Assert Assert.IsTrue(elapsedTime >= 0.75 && elapsedTime < 0.780); }