Skip to content

Commit 793a11e

Browse files
committed
ci(audience): add Editor-tests workflow + close test-discovery gap (SDK-326)
Audience package's Unity-dependent tests have never run in CI: test-audience-sdk.yml's csproj excludes Tests/Runtime/Unity/** and Tests/Editor/**, and test-audience-sample-app.yml never discovered the package's tests because manifest.json had no testables entry. DeviceCollectorTests has shipped with two compile errors that no PR caught. * Add testables entry — sample app workflow now picks up Immutable.Audience.Runtime.Tests via its existing PlayMode cells (StandaloneOSX/Win64), which also gives them IL2CPP coverage. * New test-audience-sdk-editor.yml — runs Immutable.Audience.Editor.Tests (e.g. iOSInfoPlistPostProcessor). Editor-only asmdef + UnityEditor.iOS.Xcode dependency means it can't run in the sample app's PlayMode cells. * Add InternalsVisibleTo on Immutable.Audience.Unity for the test asmdef so DeviceCollectorTests can see DeviceCollector and IDFVBridge. * Fix DeviceCollectorTests' is-not-string-s pattern: the negated form doesn't bind s, so CS0165 fires once compilation actually runs.
1 parent e6abbbd commit 793a11e

9 files changed

Lines changed: 94 additions & 14 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Audience package — Editor Tests
2+
3+
# Runs Immutable.Audience.Editor.Tests (e.g. iOSInfoPlistPostProcessor).
4+
# Editor-only asmdef + UnityEditor.iOS.Xcode dependency means it can't run
5+
# in test-audience-sample-app.yml's StandaloneOSX/Win64 PlayMode cells.
6+
# Runtime.Tests are covered there via the manifest.json testables entry.
7+
8+
on:
9+
push:
10+
branches: [main]
11+
paths:
12+
- 'src/Packages/Audience/**'
13+
- 'examples/audience/Packages/manifest.json'
14+
- '.github/workflows/test-audience-sdk-editor.yml'
15+
pull_request:
16+
paths:
17+
- 'src/Packages/Audience/**'
18+
- 'examples/audience/Packages/manifest.json'
19+
- '.github/workflows/test-audience-sdk-editor.yml'
20+
21+
jobs:
22+
editmode:
23+
if: github.event.pull_request.head.repo.fork == false || github.event_name == 'workflow_dispatch'
24+
name: EditMode (Unity 2022.3 / iOS module)
25+
runs-on: ubuntu-latest-8-cores
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
lfs: true
31+
32+
- uses: actions/cache@v4
33+
with:
34+
path: examples/audience/Library
35+
key: Library-audience-editor-tests-${{ hashFiles('examples/audience/Packages/**', 'examples/audience/ProjectSettings/**', 'src/Packages/Audience/**') }}
36+
restore-keys: |
37+
Library-audience-editor-tests-
38+
39+
- uses: game-ci/unity-test-runner@v4
40+
env:
41+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
42+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
43+
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
44+
with:
45+
unityVersion: 2022.3.62f2
46+
targetPlatform: iOS
47+
projectPath: examples/audience
48+
testMode: editmode
49+
customParameters: -assemblyNames Immutable.Audience.Editor.Tests
50+
checkName: Audience Editor Tests
51+
artifactsPath: artifacts
52+
53+
- uses: actions/upload-artifact@v4
54+
if: always()
55+
with:
56+
name: audience-editor-test-results
57+
path: artifacts

examples/audience/Packages/manifest.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
"com.unity.modules.vr": "1.0.0",
3838
"com.unity.modules.wind": "1.0.0",
3939
"com.unity.modules.xr": "1.0.0"
40-
}
40+
},
41+
"testables": [
42+
"com.immutable.audience"
43+
]
4144
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("Immutable.Audience.Runtime.Tests")]

src/Packages/Audience/Runtime/Unity/AssemblyInfo.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,34 @@ internal class ImmutableAudienceTests
1515
{
1616
private string _testDir;
1717

18+
// AudienceUnityHooks.Install installs these at SubsystemRegistration
19+
// (once per Unity process). The fixture has tests that overwrite them
20+
// mid-test, so capture+restore around each test instead of nulling —
21+
// nulling breaks downstream test fixtures sharing the same Unity
22+
// process (e.g. the sample app PlayMode tests, which assume the
23+
// default persistentDataPath provider stays installed).
24+
private System.Func<string> _origDefaultPersistentDataPathProvider;
25+
private System.Func<System.Collections.Generic.IReadOnlyDictionary<string, object>> _origLaunchContextProvider;
26+
private System.Func<System.Collections.Generic.IReadOnlyDictionary<string, object>> _origContextProvider;
27+
1828
[SetUp]
1929
public void SetUp()
2030
{
2131
_testDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
2232
Directory.CreateDirectory(_testDir);
33+
34+
_origDefaultPersistentDataPathProvider = ImmutableAudience.DefaultPersistentDataPathProvider;
35+
_origLaunchContextProvider = ImmutableAudience.LaunchContextProvider;
36+
_origContextProvider = ImmutableAudience.ContextProvider;
2337
}
2438

2539
[TearDown]
2640
public void TearDown()
2741
{
2842
ImmutableAudience.ResetState();
29-
ImmutableAudience.LaunchContextProvider = null;
30-
ImmutableAudience.ContextProvider = null;
31-
ImmutableAudience.DefaultPersistentDataPathProvider = null;
43+
ImmutableAudience.LaunchContextProvider = _origLaunchContextProvider;
44+
ImmutableAudience.ContextProvider = _origContextProvider;
45+
ImmutableAudience.DefaultPersistentDataPathProvider = _origDefaultPersistentDataPathProvider;
3246
Identity.Reset(_testDir);
3347
if (Directory.Exists(_testDir))
3448
Directory.Delete(_testDir, recursive: true);

src/Packages/Audience/Tests/Runtime/OfflineResilienceTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ public void SetUp()
2525
public void TearDown()
2626
{
2727
ImmutableAudience.ResetState();
28-
ImmutableAudience.LaunchContextProvider = null;
29-
ImmutableAudience.ContextProvider = null;
30-
ImmutableAudience.DefaultPersistentDataPathProvider = null;
3128
Identity.Reset(_testDir);
3229
// Restore queue dir (a test may have left it as a file).
3330
var queueDir = AudiencePaths.QueueDir(_testDir);

src/Packages/Audience/Tests/Runtime/PublishableKeyPrefixTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ public void SetUp()
2626
public void TearDown()
2727
{
2828
ImmutableAudience.ResetState();
29-
ImmutableAudience.LaunchContextProvider = null;
30-
ImmutableAudience.ContextProvider = null;
31-
ImmutableAudience.DefaultPersistentDataPathProvider = null;
3229
Identity.Reset(_testDir);
3330
if (Directory.Exists(_testDir))
3431
Directory.Delete(_testDir, recursive: true);

src/Packages/Audience/Tests/Runtime/ThreadSafetyStressTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ public void SetUp()
2727
public void TearDown()
2828
{
2929
ImmutableAudience.ResetState();
30-
ImmutableAudience.LaunchContextProvider = null;
31-
ImmutableAudience.ContextProvider = null;
32-
ImmutableAudience.DefaultPersistentDataPathProvider = null;
3330
Identity.Reset(_testDir);
3431
if (Directory.Exists(_testDir))
3532
Directory.Delete(_testDir, recursive: true);

src/Packages/Audience/Tests/Runtime/Unity/DeviceCollectorTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public void CollectGameLaunchProperties_StringFields_DoNotExceed256Chars()
6868
"platform", "version", "buildGuid", "unityVersion",
6969
"osFamily", "deviceModel", "gpu", "gpuVendor", "cpu" })
7070
{
71-
if (!props.TryGetValue(key, out var val) || val is not string s) continue;
71+
if (!props.TryGetValue(key, out var val)) continue;
72+
if (val is not string s) continue;
7273
Assert.LessOrEqual(s.Length, 256, $"props[{key}] exceeds 256 chars");
7374
}
7475
}

0 commit comments

Comments
 (0)