Skip to content

Instantly share code, notes, and snippets.

@AlexMerzlikin
Created October 22, 2023 20:55
Show Gist options
  • Save AlexMerzlikin/fa9f8aad18c37b73765d92ece090cabb to your computer and use it in GitHub Desktop.
Save AlexMerzlikin/fa9f8aad18c37b73765d92ece090cabb to your computer and use it in GitHub Desktop.
CustomEcsTestsFixture.cs that extends ECSTestsFixture provided by Unity Technologies. It is used to provide all the functionality to run unit tests on systems in Unity ECS
using Unity.Entities;
using Unity.Entities.Tests;
namespace Roguelite.Tests.Infrastructure
{
public class CustomEcsTestsFixture : ECSTestsFixture
{
private const int EntityCount = 1000;
protected EntityManager Manager => m_Manager;
protected void UpdateSystem<T>() where T : unmanaged, ISystem
{
World.GetExistingSystem<T>().Update(World.Unmanaged);
}
protected SystemHandle CreateSystem<T>() where T : unmanaged, ISystem => World.CreateSystem<T>();
protected Entity CreateEntity(params ComponentType[] types) => Manager.CreateEntity(types);
protected void CreateEntities(ComponentType[] types, int entityCount = EntityCount)
{
for (var i = 0; i < entityCount; i++)
{
Manager.CreateEntity(types);
}
}
protected void CreateEntityCommandBufferSystem()
{
World.CreateSystem<EndSimulationEntityCommandBufferSystem>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment