From a0142f7c25eca0ed4216d7be0127e33d74ab8efc Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Thu, 2 Oct 2025 03:58:55 +0900 Subject: [PATCH 1/2] Fix flaky tests --- Tests/Runtime/Operators/UguiDoubleClickOperatorTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Runtime/Operators/UguiDoubleClickOperatorTest.cs b/Tests/Runtime/Operators/UguiDoubleClickOperatorTest.cs index dee63f0..3936c92 100644 --- a/Tests/Runtime/Operators/UguiDoubleClickOperatorTest.cs +++ b/Tests/Runtime/Operators/UguiDoubleClickOperatorTest.cs @@ -243,7 +243,7 @@ public async Task OperateAsync_DoubleClickSequenceAndTiming_CorrectInterval() Assert.That(spy.ClickCount, Is.EqualTo(2)); var interval = (spy.ClickTimestamps[1] - spy.ClickTimestamps[0]).TotalMilliseconds; - Assert.That(interval, Is.GreaterThan(49).And.LessThan(200)); + Assert.That(interval, Is.GreaterThan(17).And.LessThan(200)); } [Test] From 87fbf306252ae594fe9afa355f55bf591c3949b8 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 25 Oct 2025 05:01:51 +0900 Subject: [PATCH 2/2] Fix flaky tests --- .../Operators/UguiDragAndDropOperatorTest.cs | 5 +++- .../Operators/UguiScrollWheelOperatorTest.cs | 13 ++++++----- .../Operators/UguiSwipeOperatorTest.cs | 23 ++++++++++--------- Tests/Runtime/TestDoubles/SpyOnDragHandler.cs | 4 +++- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Tests/Runtime/Operators/UguiDragAndDropOperatorTest.cs b/Tests/Runtime/Operators/UguiDragAndDropOperatorTest.cs index b072f3f..4cfa1a4 100644 --- a/Tests/Runtime/Operators/UguiDragAndDropOperatorTest.cs +++ b/Tests/Runtime/Operators/UguiDragAndDropOperatorTest.cs @@ -16,6 +16,8 @@ namespace TestHelper.UI.Operators [TestFixture] public class UguiDragAndDropOperatorTest { + private const int RandomTestRepeatCount = 10; + private readonly IOperator _sut = new UguiDragAndDropOperator(); private Vector3 _objectPosition; @@ -263,6 +265,7 @@ public async Task OperateAsync_ExistDropHandlerObject_DropOnTarget() [Test] [LoadScene("../../Scenes/Canvas.unity")] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_NotExistDropTarget_DropOnRandomScreenPoint() { var dragHandler = CreateSpyDragHandler(); @@ -278,7 +281,7 @@ public async Task OperateAsync_NotExistDropTarget_DropOnRandomScreenPoint() Assert.That(dragHandler.WasInitializePotentialDrag, Is.True); Assert.That(dragHandler.WasBeginDrag, Is.True); Assert.That(dragHandler.WasEndDrag, Is.True); - Assert.That(dragHandler.LastDragPosition, Is.Not.EqualTo(default(Vector2))); + Assert.That(dragHandler.LastDragPosition, Is.Not.EqualTo(SpyOnDragHandler.LastDragPositionInitialValue)); Assert.That(pointerUpHandler.WasOnPointerUp, Is.True); } diff --git a/Tests/Runtime/Operators/UguiScrollWheelOperatorTest.cs b/Tests/Runtime/Operators/UguiScrollWheelOperatorTest.cs index b01975a..a84ce3c 100644 --- a/Tests/Runtime/Operators/UguiScrollWheelOperatorTest.cs +++ b/Tests/Runtime/Operators/UguiScrollWheelOperatorTest.cs @@ -22,6 +22,7 @@ namespace TestHelper.UI.Operators public class UguiScrollWheelOperatorTest { private const string TestScene = "../../Scenes/ScrollViews.unity"; + private const int RandomTestRepeatCount = 10; private readonly IOperator _sut = new UguiScrollWheelOperator(); private GameObject _scrollView; @@ -341,7 +342,7 @@ public async Task OperateAsync_WithDestination_Scrolled(float x, float y) [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirectionAndDistance_ScrollRectBoth_RandomScrolling() { var scrollRect = _scrollView.GetComponent(); @@ -356,7 +357,7 @@ public async Task OperateAsync_WithoutDirectionAndDistance_ScrollRectBoth_Random [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirectionAndDistance_ScrollRectHorizontal_RandomScrollingHorizontal() { var spyLogger = new SpyLogger(); @@ -369,7 +370,7 @@ public async Task OperateAsync_WithoutDirectionAndDistance_ScrollRectHorizontal_ [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirectionAndDistance_ScrollRectVertical_RandomScrollingVertical() { var spyLogger = new SpyLogger(); @@ -382,7 +383,7 @@ public async Task OperateAsync_WithoutDirectionAndDistance_ScrollRectVertical_Ra [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirectionAndDistance_ScrollbarHorizontal_RandomScrollingHorizontal() { var spyLogger = new SpyLogger(); @@ -395,7 +396,7 @@ public async Task OperateAsync_WithoutDirectionAndDistance_ScrollbarHorizontal_R [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirectionAndDistance_ScrollbarVertical_RandomScrollingVertical() { var spyLogger = new SpyLogger(); @@ -408,7 +409,7 @@ public async Task OperateAsync_WithoutDirectionAndDistance_ScrollbarVertical_Ran [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirectionAndDistance_NotScrollRectOrScrollbar_RandomScrolling() { var gameObject = new GameObject(null, typeof(Image)); diff --git a/Tests/Runtime/Operators/UguiSwipeOperatorTest.cs b/Tests/Runtime/Operators/UguiSwipeOperatorTest.cs index 46c9aa5..bb12bbe 100644 --- a/Tests/Runtime/Operators/UguiSwipeOperatorTest.cs +++ b/Tests/Runtime/Operators/UguiSwipeOperatorTest.cs @@ -22,6 +22,7 @@ namespace TestHelper.UI.Operators public class UguiSwipeOperatorTest { private const string TestScene = "../../Scenes/ScrollViews.unity"; + private const int RandomTestRepeatCount = 10; private readonly ISwipeOperator _sut = new UguiSwipeOperator(); private GameObject _scrollView; @@ -359,15 +360,15 @@ public async Task OperateAsync_WithDirection_Swiped(Vector2 direction, int dista [LoadScene(TestScene)] public async Task OperateAsync_OnDragCalled() { - var spyEventHandler = _scrollView.AddComponent(); + var spyDragHandler = _scrollView.AddComponent(); var sut = new UguiSwipeOperator(); await sut.OperateAsync(_scrollView, Vector2.up); - Assert.That(spyEventHandler.WasInitializePotentialDrag, Is.True); - Assert.That(spyEventHandler.WasBeginDrag, Is.True); - Assert.That(spyEventHandler.WasEndDrag, Is.True); - Assert.That(spyEventHandler.LastDragPosition, Is.Not.EqualTo(Vector2.zero)); + Assert.That(spyDragHandler.WasInitializePotentialDrag, Is.True); + Assert.That(spyDragHandler.WasBeginDrag, Is.True); + Assert.That(spyDragHandler.WasEndDrag, Is.True); + Assert.That(spyDragHandler.LastDragPosition, Is.Not.EqualTo(SpyOnDragHandler.LastDragPositionInitialValue)); } [Test] @@ -386,7 +387,7 @@ public async Task OperateAsync_OnPointerDownAndUpCalled() [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirection_ScrollRectBoth_RandomSwipe() { const int SwipeDistance = 200; @@ -402,7 +403,7 @@ public async Task OperateAsync_WithoutDirection_ScrollRectBoth_RandomSwipe() [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirection_ScrollRectHorizontal_RandomSwipeHorizontal() { var spyLogger = new SpyLogger(); @@ -415,7 +416,7 @@ public async Task OperateAsync_WithoutDirection_ScrollRectHorizontal_RandomSwipe [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirection_ScrollRectVertical_RandomSwipeVertical() { var spyLogger = new SpyLogger(); @@ -428,7 +429,7 @@ public async Task OperateAsync_WithoutDirection_ScrollRectVertical_RandomSwipeVe [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirection_ScrollbarHorizontal_RandomSwipeHorizontal() { var spyLogger = new SpyLogger(); @@ -441,7 +442,7 @@ public async Task OperateAsync_WithoutDirection_ScrollbarHorizontal_RandomSwipeH [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirection_ScrollbarVertical_RandomSwipeVertical() { var spyLogger = new SpyLogger(); @@ -454,7 +455,7 @@ public async Task OperateAsync_WithoutDirection_ScrollbarVertical_RandomSwipeVer [Test] [LoadScene(TestScene)] - [Repeat(10)] + [Repeat(RandomTestRepeatCount)] public async Task OperateAsync_WithoutDirection_NotScrollRectOrScrollbar_RandomSwipe() { const int SwipeDistance = 200; diff --git a/Tests/Runtime/TestDoubles/SpyOnDragHandler.cs b/Tests/Runtime/TestDoubles/SpyOnDragHandler.cs index d0ae7f9..9358289 100644 --- a/Tests/Runtime/TestDoubles/SpyOnDragHandler.cs +++ b/Tests/Runtime/TestDoubles/SpyOnDragHandler.cs @@ -12,10 +12,12 @@ namespace TestHelper.UI.TestDoubles public class SpyOnDragHandler : MonoBehaviour, IInitializePotentialDragHandler, IBeginDragHandler, IEndDragHandler, IDragHandler { + public static readonly Vector2 LastDragPositionInitialValue = new Vector2(float.MinValue, float.MinValue); + public bool WasInitializePotentialDrag { get; private set; } public bool WasBeginDrag { get; private set; } public bool WasEndDrag { get; private set; } - public Vector2 LastDragPosition { get; private set; } + public Vector2 LastDragPosition { get; private set; } = LastDragPositionInitialValue; private Image _image; private GameObject _draggingObject;