Skip to main content

Enumerated Execution

.NET only

Enumerated execution is a .NET (Xcepto.NET) feature for frame-spaced environments such as Unity.

Xcepto supports enumerated execution for environments where work must advance over frames or ticks through IEnumerator — primarily Unity game engine tests.

When to use enumerated execution

Use XceptoTest.GivenEnumerated when:

  • The test runs in a Unity [UnityTest]
  • The host environment drives execution frame-by-frame
  • Blocking calls are forbidden — the test runner must yield between frames

Do not use enumerated execution for standard .NET test runners (NUnit, xUnit, MSTest). Use the normal async/await form instead.

Unity test example

[UnityTest]
public IEnumerator GameEntity_ReachesActiveState()
{
var username = "player-one";
var password = "ValidPass1!";

yield return XceptoTest.GivenEnumerated(
new GameScenario(),
builder =>
{
var ssr = builder.SsrAdapterBuilder()
.WithBaseUrl(new Uri("https://game.example.local"))
.Build();

ssr.Post("/auth/login")
.WithFormContent(
new LoginRequest(username, password).ToForm())
.AssertSuccess();

ssr.Get("/game/state")
.AssertThatResponseContentString(
body => body.Contains("\"state\":\"active\""));
});
}

Key constraints

  • GivenEnumerated returns IEnumerator, not Taskyield return it in the Unity test
  • Do not use .Wait(), .Result, Thread.Sleep, or any blocking call in enumerated test utilities
  • Preserve the IEnumerator flow — every state evaluation advances on a frame boundary
  • Scenario Initialize and state execution yield between frames automatically

EnumeratedExecutionStrategy

Internally, XceptoTest.GivenEnumerated uses EnumeratedExecutionStrategy instead of AsyncExecutionStrategy. If you are wrapping Xcepto with a custom test runner, you can instantiate this strategy directly:

var runner = new EnumeratedTestRunner(
new EnumeratedExecutionStrategy(),
scenario,
timeoutConfig,
builder => { /* ... */ });

yield return runner;