System Tests: Setting DeltaTime?

Hi all,

I’d be grateful for some feedback on how to set DeltaTime when testing systems.

The way I am doing it now. An example test:
GravitySystemTest.cs

[TestFixture]
public class GravitySystemTest : BaseTest<GravitySystem>
{
    [Test]
    public void gravityConstantTest()
    {
        Assert.AreEqual(new float3(0, -9.81f, 0), s.gravity);
    }

    [Test]
    public void simplePhysicsStaysTheSameTest()
    {
        var entity        = em.CreateEntity(typeof(global::BUD.Components.Physics.SimplePhysics), typeof(Velocity));
        var velocityValue = em.GetComponentData<Velocity>(entity).Value;

        World.Update();

        Assert.AreNotEqual(em.GetComponentData<Velocity>(entity).Value, velocityValue);
        Assert.AreEqual(em.GetComponentData<Velocity>(entity).Value.x, velocityValue.x);
        Assert.Less(em.GetComponentData<Velocity>(entity).Value.y, velocityValue.y);
        Assert.AreEqual(em.GetComponentData<Velocity>(entity).Value.z, velocityValue.z);
    }
}

And the BaseTest class:
BaseTest.cs

public class BaseTest<T> : ECSTestsFixture where T : class
{
    protected EntityManager em;
    public    T             s;

    [SetUp]
    public override void Setup()
    {
        base.Setup();

        em = m_Manager;
        s  = World.GetOrCreateSystem(typeof(T)) as T;

        var group = World.GetOrCreateSystem<SimulationSystemGroup>();
        group.AddSystemToUpdateList(s as ComponentSystemBase);

        World.SetTime(new TimeData(1.234, 0.016f)); // TODO Is this the way to go?
    }
}

So I am using World.SetTime(new TimeData(1.234, 0.016f)) to set a fixed dt value before running each test. Is this the way to go or is there a better way to do this?

That’s exactly the way to do it

1 Like

Thanks, @tertle !