fix(bmgd): improve E2E testing infrastructure robustness
- Add WaitForValueApprox overloads for float/double comparisons - Fix assembly definition to use precompiledReferences for test runners - Fix CaptureOnFailure to yield before screenshot capture (main thread) - Add error handling to test file cleanup with try/catch - Fix ClickButton to use FindObjectsByType and check scene.isLoaded - Add engine-specific output paths (Unity/Unreal/Godot) to workflow - Fix knowledge_fragments paths to use correct relative paths
This commit is contained in:
parent
16190f7a04
commit
04cc4ce55c
|
|
@ -472,6 +472,8 @@ public static class AsyncAssert
|
|||
|
||||
/// <summary>
|
||||
/// Wait for a specific value, with descriptive failure.
|
||||
/// Note: For floating-point comparisons, use WaitForValueApprox instead
|
||||
/// to handle precision issues. This method uses exact equality.
|
||||
/// </summary>
|
||||
public static IEnumerator WaitForValue<T>(
|
||||
Func<T> getter,
|
||||
|
|
@ -485,6 +487,38 @@ public static class AsyncAssert
|
|||
timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for a float value within tolerance (handles floating-point precision).
|
||||
/// </summary>
|
||||
public static IEnumerator WaitForValueApprox(
|
||||
Func<float> getter,
|
||||
float expected,
|
||||
string description,
|
||||
float tolerance = 0.0001f,
|
||||
float timeout = 5f)
|
||||
{
|
||||
yield return WaitUntil(
|
||||
() => Mathf.Abs(expected - getter()) < tolerance,
|
||||
$"{description} to equal ~{expected} ±{tolerance} (current: {getter()})",
|
||||
timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for a double value within tolerance (handles floating-point precision).
|
||||
/// </summary>
|
||||
public static IEnumerator WaitForValueApprox(
|
||||
Func<double> getter,
|
||||
double expected,
|
||||
string description,
|
||||
double tolerance = 0.0001,
|
||||
float timeout = 5f)
|
||||
{
|
||||
yield return WaitUntil(
|
||||
() => Math.Abs(expected - getter()) < tolerance,
|
||||
$"{description} to equal ~{expected} ±{tolerance} (current: {getter()})",
|
||||
timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for an event to fire.
|
||||
/// </summary>
|
||||
|
|
@ -642,7 +676,22 @@ public IEnumerator SaveLoad_PreservesGameState()
|
|||
"Movement points should be preserved");
|
||||
|
||||
// Cleanup
|
||||
System.IO.File.Delete(GameState.GetSavePath(savePath));
|
||||
var savedFilePath = GameState.GetSavePath(savePath);
|
||||
if (System.IO.File.Exists(savedFilePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
System.IO.File.Delete(savedFilePath);
|
||||
}
|
||||
catch (System.IO.IOException ex)
|
||||
{
|
||||
Debug.LogWarning($"[E2E] Failed to delete test save file '{savedFilePath}': {ex.Message}");
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
Debug.LogWarning($"[E2E] Access denied deleting test save file '{savedFilePath}': {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -744,12 +793,17 @@ Tests/
|
|||
{
|
||||
"name": "E2E",
|
||||
"references": [
|
||||
"GameAssembly",
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner"
|
||||
"GameAssembly"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll",
|
||||
"UnityEngine.TestRunner.dll",
|
||||
"UnityEditor.TestRunner.dll"
|
||||
],
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
|
|
@ -796,16 +850,18 @@ Capture screenshots and logs on failure:
|
|||
[UnityTearDown]
|
||||
public IEnumerator CaptureOnFailure()
|
||||
{
|
||||
// Yield first to ensure we're on the main thread for screenshot capture
|
||||
yield return null;
|
||||
|
||||
if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
|
||||
{
|
||||
var screenshot = ScreenCapture.CaptureScreenshotAsTexture();
|
||||
var bytes = screenshot.EncodeToPNG();
|
||||
var path = $"TestResults/Screenshots/{TestContext.CurrentContext.Test.Name}.png";
|
||||
System.IO.File.WriteAllBytes(path, bytes);
|
||||
var screenshotPath = $"TestResults/Screenshots/{TestContext.CurrentContext.Test.Name}.png";
|
||||
System.IO.File.WriteAllBytes(screenshotPath, bytes);
|
||||
|
||||
Debug.Log($"[E2E FAILURE] Screenshot saved: {path}");
|
||||
Debug.Log($"[E2E FAILURE] Screenshot saved: {screenshotPath}");
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -67,11 +67,12 @@
|
|||
## Assembly Definition
|
||||
|
||||
- [ ] References main game assembly
|
||||
- [ ] References UnityEngine.TestRunner
|
||||
- [ ] References UnityEditor.TestRunner
|
||||
- [ ] References Unity.InputSystem (if applicable)
|
||||
- [ ] `overrideReferences` set to true
|
||||
- [ ] `precompiledReferences` includes nunit.framework.dll
|
||||
- [ ] `precompiledReferences` includes UnityEngine.TestRunner.dll
|
||||
- [ ] `precompiledReferences` includes UnityEditor.TestRunner.dll
|
||||
- [ ] `UNITY_INCLUDE_TESTS` define constraint set
|
||||
- [ ] nunit.framework.dll in precompiled references
|
||||
|
||||
## Verification
|
||||
|
||||
|
|
|
|||
|
|
@ -122,8 +122,6 @@ Tests/PlayMode/E2E/
|
|||
"rootNamespace": "{ProjectNamespace}.Tests.E2E",
|
||||
"references": [
|
||||
"{GameAssemblyName}",
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"Unity.InputSystem",
|
||||
"Unity.InputSystem.TestFramework"
|
||||
],
|
||||
|
|
@ -132,7 +130,9 @@ Tests/PlayMode/E2E/
|
|||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
"nunit.framework.dll",
|
||||
"UnityEngine.TestRunner.dll",
|
||||
"UnityEditor.TestRunner.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
|
|
@ -477,11 +477,12 @@ namespace {Namespace}.Tests.E2E
|
|||
|
||||
if (button == null)
|
||||
{
|
||||
// Try searching in inactive objects
|
||||
var buttons = Resources.FindObjectsOfTypeAll<UnityEngine.UI.Button>();
|
||||
// Search in inactive objects within loaded scenes only
|
||||
var buttons = Object.FindObjectsByType<UnityEngine.UI.Button>(
|
||||
FindObjectsInactive.Include, FindObjectsSortMode.None);
|
||||
foreach (var b in buttons)
|
||||
{
|
||||
if (b.name == buttonName)
|
||||
if (b.name == buttonName && b.gameObject.scene.isLoaded)
|
||||
{
|
||||
button = b;
|
||||
break;
|
||||
|
|
@ -490,7 +491,12 @@ namespace {Namespace}.Tests.E2E
|
|||
}
|
||||
|
||||
UnityEngine.Assertions.Assert.IsNotNull(button,
|
||||
$"Button '{buttonName}' not found");
|
||||
$"Button '{buttonName}' not found in active scenes");
|
||||
|
||||
if (!button.interactable)
|
||||
{
|
||||
Debug.LogWarning($"[InputSimulator] Button '{buttonName}' is not interactable");
|
||||
}
|
||||
|
||||
button.onClick.Invoke();
|
||||
yield return null;
|
||||
|
|
@ -697,6 +703,8 @@ namespace {Namespace}.Tests.E2E
|
|||
|
||||
/// <summary>
|
||||
/// Wait for a value to equal expected.
|
||||
/// Note: For floating-point comparisons, use WaitForValueApprox instead
|
||||
/// to handle precision issues. This method uses exact equality.
|
||||
/// </summary>
|
||||
public static IEnumerator WaitForValue<T>(
|
||||
Func<T> getter,
|
||||
|
|
@ -710,6 +718,38 @@ namespace {Namespace}.Tests.E2E
|
|||
timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for a float value within tolerance (handles floating-point precision).
|
||||
/// </summary>
|
||||
public static IEnumerator WaitForValueApprox(
|
||||
Func<float> getter,
|
||||
float expected,
|
||||
string description,
|
||||
float tolerance = 0.0001f,
|
||||
float timeout = 5f)
|
||||
{
|
||||
yield return WaitUntil(
|
||||
() => Mathf.Abs(expected - getter()) < tolerance,
|
||||
$"{description} to equal ~{expected} ±{tolerance} (current: {getter()})",
|
||||
timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for a double value within tolerance (handles floating-point precision).
|
||||
/// </summary>
|
||||
public static IEnumerator WaitForValueApprox(
|
||||
Func<double> getter,
|
||||
double expected,
|
||||
string description,
|
||||
double tolerance = 0.0001,
|
||||
float timeout = 5f)
|
||||
{
|
||||
yield return WaitUntil(
|
||||
() => Math.Abs(expected - getter()) < tolerance,
|
||||
$"{description} to equal ~{expected} ±{tolerance} (current: {getter()})",
|
||||
timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for a value to not equal a specific value.
|
||||
/// </summary>
|
||||
|
|
@ -835,6 +875,8 @@ namespace {Namespace}.Tests.E2E
|
|||
Assert.IsNotNull(Scenario, "ScenarioBuilder should be available");
|
||||
|
||||
// Verify game is actually ready
|
||||
// NOTE: {IsReadyProperty} is a template placeholder. Replace it with your
|
||||
// game's actual ready-state property (e.g., IsReady, IsInitialized, HasLoaded).
|
||||
yield return AsyncAssert.WaitUntil(
|
||||
() => GameState.{IsReadyProperty},
|
||||
"Game should be in ready state");
|
||||
|
|
|
|||
|
|
@ -24,11 +24,12 @@ workflow:
|
|||
- "Game has identifiable state manager"
|
||||
- "Main gameplay scene exists"
|
||||
|
||||
# Paths are relative to this workflow file's location
|
||||
knowledge_fragments:
|
||||
- "knowledge/e2e-testing.md"
|
||||
- "knowledge/unity-testing.md"
|
||||
- "knowledge/unreal-testing.md"
|
||||
- "knowledge/godot-testing.md"
|
||||
- "../../../gametest/knowledge/e2e-testing.md"
|
||||
- "../../../gametest/knowledge/unity-testing.md"
|
||||
- "../../../gametest/knowledge/unreal-testing.md"
|
||||
- "../../../gametest/knowledge/godot-testing.md"
|
||||
|
||||
inputs:
|
||||
game_state_class:
|
||||
|
|
@ -52,7 +53,10 @@ workflow:
|
|||
- "godot-input"
|
||||
- "custom"
|
||||
|
||||
# Output paths vary by engine. Generate files matching detected engine.
|
||||
outputs:
|
||||
unity:
|
||||
condition: "engine == 'unity'"
|
||||
infrastructure_files:
|
||||
description: "Generated E2E infrastructure classes"
|
||||
files:
|
||||
|
|
@ -60,22 +64,62 @@ workflow:
|
|||
- "Tests/PlayMode/E2E/Infrastructure/ScenarioBuilder.cs"
|
||||
- "Tests/PlayMode/E2E/Infrastructure/InputSimulator.cs"
|
||||
- "Tests/PlayMode/E2E/Infrastructure/AsyncAssert.cs"
|
||||
|
||||
assembly_definition:
|
||||
description: "E2E test assembly configuration"
|
||||
files:
|
||||
- "Tests/PlayMode/E2E/E2E.asmdef"
|
||||
|
||||
example_test:
|
||||
description: "Working example E2E test"
|
||||
files:
|
||||
- "Tests/PlayMode/E2E/ExampleE2ETest.cs"
|
||||
|
||||
documentation:
|
||||
description: "E2E testing README"
|
||||
files:
|
||||
- "Tests/PlayMode/E2E/README.md"
|
||||
|
||||
unreal:
|
||||
condition: "engine == 'unreal'"
|
||||
infrastructure_files:
|
||||
description: "Generated E2E infrastructure classes"
|
||||
files:
|
||||
- "Source/{ProjectName}/Tests/E2E/GameE2ETestBase.h"
|
||||
- "Source/{ProjectName}/Tests/E2E/GameE2ETestBase.cpp"
|
||||
- "Source/{ProjectName}/Tests/E2E/ScenarioBuilder.h"
|
||||
- "Source/{ProjectName}/Tests/E2E/ScenarioBuilder.cpp"
|
||||
- "Source/{ProjectName}/Tests/E2E/InputSimulator.h"
|
||||
- "Source/{ProjectName}/Tests/E2E/InputSimulator.cpp"
|
||||
- "Source/{ProjectName}/Tests/E2E/AsyncAssert.h"
|
||||
build_configuration:
|
||||
description: "E2E test build configuration"
|
||||
files:
|
||||
- "Source/{ProjectName}/Tests/E2E/{ProjectName}E2ETests.Build.cs"
|
||||
example_test:
|
||||
description: "Working example E2E test"
|
||||
files:
|
||||
- "Source/{ProjectName}/Tests/E2E/ExampleE2ETest.cpp"
|
||||
documentation:
|
||||
description: "E2E testing README"
|
||||
files:
|
||||
- "Source/{ProjectName}/Tests/E2E/README.md"
|
||||
|
||||
godot:
|
||||
condition: "engine == 'godot'"
|
||||
infrastructure_files:
|
||||
description: "Generated E2E infrastructure classes"
|
||||
files:
|
||||
- "tests/e2e/infrastructure/game_e2e_test_fixture.gd"
|
||||
- "tests/e2e/infrastructure/scenario_builder.gd"
|
||||
- "tests/e2e/infrastructure/input_simulator.gd"
|
||||
- "tests/e2e/infrastructure/async_assert.gd"
|
||||
example_test:
|
||||
description: "Working example E2E test"
|
||||
files:
|
||||
- "tests/e2e/scenarios/example_e2e_test.gd"
|
||||
documentation:
|
||||
description: "E2E testing README"
|
||||
files:
|
||||
- "tests/e2e/README.md"
|
||||
|
||||
steps:
|
||||
- id: analyze
|
||||
name: "Analyze Game Architecture"
|
||||
|
|
|
|||
Loading…
Reference in New Issue