Skip to content

Commit 4393621

Browse files
fix: Exclude test for rising animation state count during runtime builds (#2241)
* test update: only include the animation state count check when running in the editor
1 parent 8b2a8b7 commit 4393621

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

testproject/Assets/Tests/Runtime/Animation/AnimatorTestHelper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ private void Awake()
2929
m_NetworkAnimator = GetComponent<NetworkAnimator>();
3030
}
3131

32+
// Since the com.unity.netcode.components does not allow test project to access its internals
33+
// during runtime, this is only used when running test runner from within the editor
34+
#if UNITY_EDITOR
3235
internal int GetAnimatorStateCount()
3336
{
3437
return m_NetworkAnimator.GetAnimationMessage().AnimationStates.Count;
3538
}
39+
#endif
3640

3741
public override void OnNetworkSpawn()
3842
{

testproject/Assets/Tests/Runtime/Animation/NetworkAnimatorTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,13 @@ public IEnumerator TriggerUpdateTests([Values] OwnerShipMode ownerShipMode, [Val
256256
AssertOnTimeout($"Timed out waiting for the client-side instance of {GetNetworkAnimatorName(authoritativeMode)} to be spawned!");
257257
var animatorTestHelper = ownerShipMode == OwnerShipMode.ClientOwner ? AnimatorTestHelper.ClientSideInstances[m_ClientNetworkManagers[0].LocalClientId] : AnimatorTestHelper.ServerSideInstance;
258258
var layerCount = animatorTestHelper.GetAnimator().layerCount;
259-
var animationStateCount = animatorTestHelper.GetAnimatorStateCount();
260259

260+
// Since the com.unity.netcode.components does not allow test project to access its internals
261+
// during runtime, this is only used when running test runner from within the editor
262+
#if UNITY_EDITOR
263+
var animationStateCount = animatorTestHelper.GetAnimatorStateCount();
261264
Assert.True(layerCount == animationStateCount, $"AnimationState count {animationStateCount} does not equal the layer count {layerCount}!");
265+
#endif
262266
if (authoritativeMode == AuthoritativeMode.ServerAuth)
263267
{
264268
animatorTestHelper = AnimatorTestHelper.ServerSideInstance;
@@ -304,7 +308,9 @@ public IEnumerator TriggerUpdateTests([Values] OwnerShipMode ownerShipMode, [Val
304308
// Verify we only entered each state once
305309
yield return WaitForConditionOrTimeOut(() => CheckStateEnterCount.AllStatesEnteredMatch(clientIdList));
306310
AssertOnTimeout($"Timed out waiting for all states entered to match!");
307-
311+
// Since the com.unity.netcode.components does not allow test project to access its internals
312+
// during runtime, this is only used when running test runner from within the editor
313+
#if UNITY_EDITOR
308314
// Now, update some states for several seconds to assure the AnimationState count does not grow
309315
var waitForSeconds = new WaitForSeconds(0.25f);
310316
bool rotateToggle = true;
@@ -317,7 +323,7 @@ public IEnumerator TriggerUpdateTests([Values] OwnerShipMode ownerShipMode, [Val
317323
yield return waitForSeconds;
318324
rotateToggle = !rotateToggle;
319325
}
320-
326+
#endif
321327
AnimatorTestHelper.IsTriggerTest = false;
322328
VerboseDebug($" ------------------ Trigger Test [{TriggerTest.Iteration}][{ownerShipMode}] Stopping ------------------ ");
323329
}

0 commit comments

Comments
 (0)