From 763837382c0cf67c0d1c1558a90930840f3d3633 Mon Sep 17 00:00:00 2001 From: ImmutableJeffrey Date: Sat, 2 May 2026 14:53:59 +1000 Subject: [PATCH 1/9] test(audience-sample): centralise reflection field names and per-test panel-user prefix SampleAppTestHelpers reflects on AudienceSample.UI.cs's internal LogEntry struct (Label / Body / Level) and on UI Toolkit's internal Clickable.clicked field. The reflection design is deliberate: the sample-app assembly does not grant InternalsVisibleTo to the test assembly, so direct access (and nameof()) cannot reach LogEntry or Clickable.clicked. Without consts, a struct-shape change has to update three GetField call sites and the click extension separately. Adds file-local consts (LogEntryLabelField / BodyField / LevelField) inside SampleAppTestHelpers and an internal ClickableClickedField const used by the ButtonTestExtensions reflection. Migrates four GetField call sites. SampleAppLiveFireTests also reflects on the internal ImmutableAudience.ResetState method name and builds a unique userId per test run from a "panel-user-" prefix concatenated with DateTime.UtcNow.Ticks. Adds ResetStateMethodName and PanelUserPrefix consts inside the fixture and migrates both sites. Per the user's "everything random goes in a constant" stance. Follow-up to SDK-272 (centralisation of duplicated literals). --- .../Tests/Runtime/SampleAppLiveFireTests.cs | 10 ++++++++-- .../Tests/Runtime/SampleAppTestHelpers.cs | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/examples/audience/Assets/SampleApp/Tests/Runtime/SampleAppLiveFireTests.cs b/examples/audience/Assets/SampleApp/Tests/Runtime/SampleAppLiveFireTests.cs index 1565cca1d..5743f2084 100644 --- a/examples/audience/Assets/SampleApp/Tests/Runtime/SampleAppLiveFireTests.cs +++ b/examples/audience/Assets/SampleApp/Tests/Runtime/SampleAppLiveFireTests.cs @@ -13,6 +13,12 @@ namespace Immutable.Audience.Samples.SampleApp.Tests [TestFixture] internal class SampleAppLiveFireTests { + // Reflection target for ImmutableAudience.ResetState (invoked from SetUp). + private const string ResetStateMethodName = "ResetState"; + + // Per-test prefix combined with UtcNow.Ticks for a unique userId per Identify run. + private const string PanelUserPrefix = "panel-user-"; + // Cached allocations for fixed-delay yields (SDK needs time to flush // rather than "wait up to N seconds for a condition"). Static readonly // so the WaitForSecondsRealtime instance is created once per class load. @@ -28,7 +34,7 @@ public void SetUp() // ResetState is internal — reached via reflection (BindingFlags.NonPublic // bypasses C# access checks; no InternalsVisibleTo required). var t = typeof(ImmutableAudience); - var m = t.GetMethod("ResetState", + var m = t.GetMethod(ResetStateMethodName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); m?.Invoke(null, null); @@ -687,7 +693,7 @@ public IEnumerator IdentityPanel_PopulatesUserIdAfterIdentify() { yield return LoadAndInit(initialConsent: SampleAppUi.Consent.Full); - var userId = "panel-user-" + DateTime.UtcNow.Ticks; + var userId = PanelUserPrefix + DateTime.UtcNow.Ticks; _root!.Q(SampleAppUi.IdentityFields.Id).value = userId; _root.Q