Skip to main content

Unity Editor Mock Mode

Android not availableiOS not availableFlutter not availableReact Native not availableUnity ≥ 1.12.1

Run your Octopus integration inside the Unity Editor, without a device build: the SDK routes its calls through a built-in mock backend, and you can write EditMode tests against the calls it records. This mode is specific to the Unity SDK.

Before you begin​

  • Add the Octopus Unity SDK to your project: see the Quickstart.
  • For EditMode tests, set up the Unity Test Framework (NUnit) in your project.

How it works​

In the Editor, OctopusSDK does not call a native SDK. Instead:

  • Every call is recorded in a call log, OctopusSDK.Mock.Calls.
  • Navigation calls update a simulated screen, shown by an IMGUI overlay.
  • Asynchronous calls complete without a network: ConnectUser calls your token provider, then completes.
  • Driver methods of OctopusSDK.Mock fire the SDK callbacks and events on demand.

The recorded calls, by area:

AreaRecorded calls
LifecycleInitialize, SwitchCommunity, Reset, Stop, Close
UserConnectUser, DisconnectUser, RefreshEntitlements, SetHasModifyUserHandler, SetProfileInterceptionEnabled
NavigationOpen, OpenPost, OpenCreatePost, OpenGroup, OpenProfile, OpenActivity, OpenMemberActivity, OpenUrlInOctopus, SetUrlInterceptionEnabled
GroupsFetchGroups, FollowGroup, UnfollowGroup, SyncFollowGroups
BridgesFetchOrCreateClientObjectRelatedPost, StartObservingClientObjectRelatedPost, StopObservingClientObjectRelatedPost, SetReaction
Community dataFetchCommunityData, StartObservingCommunityData, StopObservingCommunityData
Analytics and A/B testingTrack, TrackAccessToCommunity, OverrideCommunityAccess
NotificationsRegisterNotificationsToken, UpdateNotSeenNotificationsCount
AppearanceSetAppName, SetLogo, SetIcons, SetFonts, SetFontWeights, SetLightColorScheme, SetDarkColorScheme, SetColorSchemeType, SetNavBarUsesPrimaryColor, SetForcedOrientation, OverrideDefaultLocale

All mock code is compiled only in the Editor (#if UNITY_EDITOR): it is absent from device builds.


1. Configure mock mode​

Mock mode is on by default: no setup is needed. To change it, set these toggles before OctopusSDK.Initialize(...):

  • OctopusSDK.Mock.Enabled: bool — false turns the mock off: the SDK is inert in the Editor.
  • OctopusSDK.Mock.ShowOverlay: bool — false hides the IMGUI overlay. It can also be changed during Play mode.
// Turn the mock off: the SDK is inert in the Editor
OctopusSDK.Mock.Enabled = false;

// Keep the mock on, but hide the IMGUI overlay
OctopusSDK.Mock.ShowOverlay = false;

OctopusSDK.Initialize("YOUR_API_KEY", ConnectionMode.SSO());

To keep the settings in your project, create an OctopusMockSettings asset at Assets/OctopusSDK/Resources/OctopusMockSettings.asset. At Initialize, its values override the toggles set in code:

SettingEffect
EnabledByDefaultWhether mock mode is on.
ShowOverlayWhether the IMGUI overlay is shown.
InitialNotSeenCountThe count returned by UpdateNotSeenNotificationsCount.
SeedGroupsThe groups returned by FetchGroups and SyncFollowGroups.

2. Drive callbacks manually​

Driver methods simulate what the native SDK would send. They fire even when Mock.Enabled is false.

DriverSimulates
EmitNotSeenCount(int count)A new count of unseen notifications.
EmitLoginRequired()The SDK asking the user to log in.
EmitGroupsChanged(IList<OctopusGroup> groups)A change of the groups.
EmitHasAccessToCommunity(bool hasAccess)A change of the user's access to the community (A/B test or override).
EmitNavigateToClientObject(string clientObjectId)A tap on a button that opens one of your client objects.
EmitNavigateToProfile(string clientUserId)A tap on a member's profile.
EmitModifyUser(ProfileField? field)The user editing a profile field inside Octopus.
EmitProfileChanged(OctopusProfile profile)An update of the user's profile, on the next Unity update.
EmitGroupAccessDenied(string groupId)The user being denied access to a group, on the Unity main thread.
EmitOctopusEvent(OctopusEvent e)An event of the SDK.
EmitOctopusEventJson(string json)An event of the SDK, from its JSON form.
EmitBridgeShareSignatureRequest(string fingerprint)The SDK asking your app to sign a Bridge Share image. The JWT your signer returns is recorded in LastBridgeShareSignature.
OctopusSDK.Mock.EmitNotSeenCount(3);
OctopusSDK.Mock.EmitLoginRequired();
OctopusSDK.Mock.EmitGroupsChanged(myGroups);
OctopusSDK.Mock.EmitHasAccessToCommunity(false);
OctopusSDK.Mock.EmitNavigateToClientObject("article_42");
OctopusSDK.Mock.EmitModifyUser(ProfileField.NICKNAME);
OctopusSDK.Mock.EmitOctopusEvent(new SessionStartedEvent { SessionId = "session_1" });

To test your error handling, set the failure the next call returns. Each one is consumed by the next matching call, then cleared; null means success.

SetterNext call that fails
NextConnectUserErrorConnectUser, callback-based form
NextGroupFollowUnfollowErrorA follow or unfollow of one group
NextSetReactionErrorSetReaction
NextClientPostErrorFetchOrCreateClientObjectRelatedPost
RefreshEntitlementsErrorRefreshEntitlements, until you set it back to null

To seed data, use SetGroups(groups) for the groups, SetClientObjectRelatedPost(objectId, post) for the post of a client object, and SetCommunityData(memberId, data) for the community data of a member.


3. Write EditMode tests​

OctopusSDK.Mock keeps a log of every call. Call OctopusSDK.Mock.Reset() in [SetUp] to clear it between tests, then check the results:

  • Typed accessors: LastOpenedPost, LastPrefilledPost, LastTrackedEvent, CurrentScreen, LastBridgeShareSignature, LastBridgeShareSignatureFailed.
  • LastCall("MethodName") — the most recent call with that name, or null.
  • Calls — an ordered IReadOnlyList<Call> of every call since the last Reset(). Each Call has a Method string and an Args array.
using NUnit.Framework;

public class MyOctopusTests
{
[SetUp]
public void SetUp()
{
// Reset() does not restore Enabled: set it again in case a test turned it off
OctopusSDK.Mock.Enabled = true;
OctopusSDK.Mock.Reset();
}

[Test]
public void OpenPost_RecordsPostId()
{
OctopusSDK.OpenPost("42");
Assert.AreEqual("42", OctopusSDK.Mock.LastOpenedPost);
}

[Test]
public void OpenCreatePost_RecordsPrefill()
{
OctopusSDK.OpenCreatePost(new OctopusPrefilledPost
{
Text = "Hello",
TopicId = "group_1"
});
Assert.AreEqual("Hello", OctopusSDK.Mock.LastPrefilledPost.Text);
Assert.AreEqual("group_1", OctopusSDK.Mock.LastPrefilledPost.TopicId);
}
}

Behavior and limits​

  • Reset() clears the call log, the current screen, the typed accessors, the failure setters and the seeded data. It does not change Enabled or ShowOverlay.
  • Events emitted with EmitOctopusEvent are raised synchronously, on the thread that calls the driver. On a device, they are raised on a background thread: see Analytics.
  • The mock does not reproduce the behavior of the backend: moderation, permissions and the content of the community are not simulated.

Next steps​

  • Analytics — listen to the events you emit with EmitOctopusEvent.
  • Events reference — the events you can simulate.
  • Bridges — the client object flows you can seed with SetClientObjectRelatedPost.