<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mindattic.com/wiki/docs/index.php?action=history&amp;feed=atom&amp;title=Unity.Multiplayer%2Farticles%2Ftesting</id>
	<title>Unity.Multiplayer/articles/testing - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mindattic.com/wiki/docs/index.php?action=history&amp;feed=atom&amp;title=Unity.Multiplayer%2Farticles%2Ftesting"/>
	<link rel="alternate" type="text/html" href="https://mindattic.com/wiki/docs/index.php?title=Unity.Multiplayer/articles/testing&amp;action=history"/>
	<updated>2026-12-05T06:50:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.3</generator>
	<entry>
		<id>https://mindattic.com/wiki/docs/index.php?title=Unity.Multiplayer/articles/testing&amp;diff=936&amp;oldid=prev</id>
		<title>Docs Sync: md2wiki: sync from MindAttic.Docs</title>
		<link rel="alternate" type="text/html" href="https://mindattic.com/wiki/docs/index.php?title=Unity.Multiplayer/articles/testing&amp;diff=936&amp;oldid=prev"/>
		<updated>2026-11-29T20:37:12Z</updated>

		<summary type="html">&lt;p&gt;md2wiki: sync from MindAttic.Docs&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Testing =&lt;br /&gt;
&lt;br /&gt;
A networked game is only as good as its tests over a real connection, so the package ships a &amp;lt;strong&amp;gt;test kit&amp;lt;/strong&amp;gt; — the &amp;lt;code&amp;gt;Unity.Multiplayer.Testing&amp;lt;/code&amp;gt; assembly — that every game uses for its own PlayMode tests, and the package tests itself with the same kit. This page starts with the kit (what a game needs), then covers the package&amp;#039;s own suites.&lt;br /&gt;
&lt;br /&gt;
== The test kit ==&lt;br /&gt;
&lt;br /&gt;
One fixture gives a test a host (or a dedicated server) and any number of clients, each a real &amp;lt;code&amp;gt;NetSession&amp;lt;/code&amp;gt; over a real Unity Transport on loopback, on a port that is free on this machine. Waits fail with a message saying what never happened, not a bare timeout.&lt;br /&gt;
&lt;br /&gt;
=== Set up ===&lt;br /&gt;
&lt;br /&gt;
# In &amp;lt;code&amp;gt;Packages/manifest.json&amp;lt;/code&amp;gt;, list &amp;lt;code&amp;gt;com.unity.netcode.gameobjects&amp;lt;/code&amp;gt; under &amp;lt;code&amp;gt;&amp;quot;testables&amp;quot;&amp;lt;/code&amp;gt;. The fixture is built on NGO&amp;#039;s &amp;lt;code&amp;gt;NetcodeIntegrationTest&amp;lt;/code&amp;gt;, which only compiles when NGO is testable. You do &amp;lt;strong&amp;gt;not&amp;lt;/strong&amp;gt; need to list &amp;lt;code&amp;gt;com.mindattic.unity.multiplayer&amp;lt;/code&amp;gt; there, so the package&amp;#039;s own suites stay out of your Test Runner.&amp;lt;br&amp;gt;&amp;lt;pre class=&amp;quot;md-code lang-json&amp;quot;&amp;gt;&amp;quot;testables&amp;quot;: [ &amp;quot;com.unity.netcode.gameobjects&amp;quot; ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Reference the kit from your PlayMode test assembly. Its define constraint is &amp;lt;code&amp;gt;UNITY_EDITOR &amp;amp;#124;&amp;amp;#124; UNITY_INCLUDE_TESTS&amp;lt;/code&amp;gt;: it compiles in the Editor and in test builds, and it (with NUnit and NGO&amp;#039;s test helpers) never reaches a player build. It also requires &amp;lt;code&amp;gt;MINDATTIC_NGO_TESTABLE&amp;lt;/code&amp;gt;, a symbol the package&amp;#039;s editor script sets while the manifest lists NGO under &amp;lt;code&amp;gt;&amp;quot;testables&amp;quot;&amp;lt;/code&amp;gt;, so a project without that line compiles fine and simply has no kit. It deliberately does not use &amp;lt;code&amp;gt;UNITY_INCLUDE_TESTS&amp;lt;/code&amp;gt; alone, which Unity honours only for packages listed under &amp;lt;code&amp;gt;testables&amp;lt;/code&amp;gt;; like Unity&amp;#039;s own Performance Testing package, it is a test utility a game uses without making the package&amp;#039;s own tests part of its Test Runner.&lt;br /&gt;
# &amp;lt;strong&amp;gt;Give every test assembly that references the kit the &amp;lt;code&amp;gt;MINDATTIC_NGO_TESTABLE&amp;lt;/code&amp;gt; constraint too, and commit the define.&amp;lt;/strong&amp;gt; The symbol is set by an editor script, and an editor script only runs after the project has compiled. On a clean checkout (a CI job, a deploy build, a teammate&amp;#039;s first clone) the define is not set yet unless it is committed, the kit is left out, and a test assembly that references it without the constraint fails the very first compile with &amp;lt;code&amp;gt;CS0234: The type or namespace name &amp;#039;Testing&amp;#039; does not exist&amp;lt;/code&amp;gt;; a batch build aborts there, before any script can fix it. So:&amp;lt;br&amp;gt;With both in place a clean checkout compiles the kit and the game&amp;#039;s tests on its first compile and changes no committed file. &amp;lt;code&amp;gt;tests/run-new-game.ps1&amp;lt;/code&amp;gt; checks exactly this: it copies the generated game&amp;#039;s committed folders (no &amp;lt;code&amp;gt;Library&amp;lt;/code&amp;gt;) and batch-builds a Win64 player from them.&amp;lt;br&amp;gt;&amp;lt;pre class=&amp;quot;md-code lang-json&amp;quot;&amp;gt;{     &amp;quot;name&amp;quot;: &amp;quot;MyGame.PlayMode.Tests&amp;quot;,     &amp;quot;references&amp;quot;: [         &amp;quot;MyGame&amp;quot;,         &amp;quot;Unity.Multiplayer&amp;quot;,         &amp;quot;Unity.Multiplayer.Core&amp;quot;,         &amp;quot;Unity.Multiplayer.Testing&amp;quot;,         &amp;quot;Unity.Netcode.Runtime&amp;quot;,         &amp;quot;Unity.Netcode.Runtime.Tests&amp;quot;,         &amp;quot;UnityEngine.TestRunner&amp;quot;,         &amp;quot;UnityEditor.TestRunner&amp;quot;     ],     &amp;quot;overrideReferences&amp;quot;: true,     &amp;quot;precompiledReferences&amp;quot;: [ &amp;quot;nunit.framework.dll&amp;quot; ],     &amp;quot;autoReferenced&amp;quot;: false,     &amp;quot;defineConstraints&amp;quot;: [ &amp;quot;UNITY_INCLUDE_TESTS&amp;quot;, &amp;quot;MINDATTIC_NGO_TESTABLE&amp;quot; ] }&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* the constraint goes in each such asmdef (the New Game template has it; for an older game the package&amp;#039;s editor script adds it to any asmdef under &amp;lt;code&amp;gt;Assets&amp;lt;/code&amp;gt; that references the kit without it, and logs which files it changed),&lt;br /&gt;
#* and &amp;lt;code&amp;gt;ProjectSettings/ProjectSettings.asset&amp;lt;/code&amp;gt;, which holds the symbol under &amp;lt;strong&amp;gt;Player Settings &amp;gt; Scripting Define Symbols&amp;lt;/strong&amp;gt; (Standalone, Server and the active platform), is committed along with &amp;lt;code&amp;gt;Packages/manifest.json&amp;lt;/code&amp;gt;. The script logs &amp;quot;Commit ProjectSettings/ProjectSettings.asset&amp;quot; whenever it changes that file; if a clean checkout&amp;#039;s build leaves &amp;lt;code&amp;gt;ProjectSettings.asset&amp;lt;/code&amp;gt; modified, the define was not committed.&lt;br /&gt;
&lt;br /&gt;
=== A first test ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;using System.Collections;&lt;br /&gt;
using NUnit.Framework;&lt;br /&gt;
using Unity.Multiplayer;&lt;br /&gt;
using Unity.Multiplayer.Core;&lt;br /&gt;
using Unity.Multiplayer.Testing;&lt;br /&gt;
using UnityEngine;&lt;br /&gt;
using UnityEngine.TestTools;&lt;br /&gt;
&lt;br /&gt;
public class ScoreBoardTests : NetSessionTest&lt;br /&gt;
{&lt;br /&gt;
    private GameObject _prefab;&lt;br /&gt;
&lt;br /&gt;
    public ScoreBoardTests() : base(Topology.Host, clients: 2) { }&lt;br /&gt;
&lt;br /&gt;
    protected override void OnSessionsCreated()&lt;br /&gt;
    {&lt;br /&gt;
        _prefab = CreatePrefab&amp;amp;lt;ScoreBoard&amp;gt;();              // a network prefab, registered on every peer&lt;br /&gt;
        Clients[0].Identity = new PlayerIdentity(&amp;quot;ann&amp;quot;, &amp;quot;Ann&amp;quot;, PlayerColor.White);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    [UnityTest]&lt;br /&gt;
    public IEnumerator EveryClientSeesTheScore()&lt;br /&gt;
    {&lt;br /&gt;
        yield return StartAndJoinAll();                      // host up, both clients connected, all on Port&lt;br /&gt;
&lt;br /&gt;
        ScoreBoard onServer = Spawn&amp;amp;lt;ScoreBoard&amp;gt;(_prefab);    // spawned by the server&lt;br /&gt;
        var onAnn = WaitForCopy(Clients[0], onServer);       // Ann&amp;#039;s copy of the same object&lt;br /&gt;
        yield return onAnn;&lt;br /&gt;
&lt;br /&gt;
        onServer.AddPoint();&lt;br /&gt;
        yield return WaitForSynced(() =&amp;gt; onAnn.Result.Score, 1, &amp;quot;Ann&amp;#039;s score&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The fixture makes fresh NetworkManagers, sessions and port for every test, and disposes them afterwards.&lt;br /&gt;
&lt;br /&gt;
=== What &amp;lt;code&amp;gt;NetSessionTest&amp;lt;/code&amp;gt; gives you ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Member&lt;br /&gt;
! What it does&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;NetSessionTest(Topology topology, int clients = 1, TransportKind transport = Udp)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;Topology.Host&amp;lt;/code&amp;gt; (a listen server, which is also a player) or &amp;lt;code&amp;gt;Topology.Server&amp;lt;/code&amp;gt; (dedicated), plus N clients. Use &amp;lt;code&amp;gt;[TestFixture(TransportKind.Udp)] [TestFixture(TransportKind.WebSocket)]&amp;lt;/code&amp;gt; to run a suite over both transports.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Server&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Clients&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Client&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Sessions&amp;lt;/code&amp;gt;&lt;br /&gt;
| The &amp;lt;code&amp;gt;NetSession&amp;lt;/code&amp;gt;s: the host or server, every client, the first client, all of them.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Port&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Transport&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Config()&amp;lt;/code&amp;gt;&lt;br /&gt;
| The free port and transport for this test, and a fresh &amp;lt;code&amp;gt;NetConfig&amp;lt;/code&amp;gt; carrying them (plus &amp;lt;code&amp;gt;GameVersion&amp;lt;/code&amp;gt;). Override &amp;lt;code&amp;gt;Config()&amp;lt;/code&amp;gt; to change every session&amp;#039;s default.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;OnSessionsCreated()&amp;lt;/code&amp;gt;&lt;br /&gt;
| Your setup hook, before anything starts: identities, protocol hashes, prefabs, event handlers.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;OnSessionsTearDown()&amp;lt;/code&amp;gt;&lt;br /&gt;
| Your teardown hook, before the sessions are disposed.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;StartServer(config)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Join(client, config)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;StartAndJoinAll(config)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Start and connect, waiting until each is up; &amp;lt;code&amp;gt;StartAndJoinAll&amp;lt;/code&amp;gt; also waits until the server sees every connection.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;CreatePrefab&amp;amp;lt;T&amp;gt;(name)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RegisterPrefab(prefab)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SetPlayerPrefab(prefab)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Network prefabs made in code or loaded from assets, registered with every session; a player prefab every connection gets.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Spawn&amp;amp;lt;T&amp;gt;(prefab, owner)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Spawns an instance on the running server, owned by a client&amp;#039;s session or by the server, and returns the server&amp;#039;s component.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;WaitUntil(condition, failure)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Waits for any condition. Pass the failure as &amp;lt;code&amp;gt;() =&amp;gt; &amp;quot;...&amp;quot;&amp;lt;/code&amp;gt; to report state at the moment it fails.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;WaitForSpawn&amp;amp;lt;T&amp;gt;(peer, owner, match)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Waits until a peer has a spawned &amp;lt;code&amp;gt;T&amp;lt;/code&amp;gt; (optionally owned by a client, matching a predicate). &amp;lt;code&amp;gt;yield return&amp;lt;/code&amp;gt; it, then read &amp;lt;code&amp;gt;.Result&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;WaitForCopy&amp;amp;lt;T&amp;gt;(peer, original)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Waits until a peer has its copy of a spawned object.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;WaitForSynced&amp;amp;lt;T&amp;gt;(read, expected, what)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Waits until a &amp;lt;code&amp;gt;[Synced]&amp;lt;/code&amp;gt; value as one peer sees it equals &amp;lt;code&amp;gt;expected&amp;lt;/code&amp;gt;; fails with the last value seen.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;WaitFor(task)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;WaitFor&amp;amp;lt;T&amp;gt;(task)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Waits for a &amp;lt;code&amp;gt;Task&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;JoinByCode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HostWithCode&amp;lt;/code&amp;gt;, ...), rethrows what it threw, and hands back its result.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;StartRendezvous(ttlSeconds)&amp;lt;/code&amp;gt;&lt;br /&gt;
| An in-process rendezvous service for join-by-code tests, disposed with the test.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;TimeoutSeconds&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SceneManagement&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;GameVersion&amp;lt;/code&amp;gt;&lt;br /&gt;
| Override to give a slow or lossy test more time (default 10 s), turn NGO scene management on, or change the default game version.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;OnServerAndClientsCreated&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;OnTearDown&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NumberOfClients&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CanStartServerAndClients&amp;lt;/code&amp;gt; are sealed: the fixture owns the session lifecycle. Everything else of &amp;lt;code&amp;gt;NetcodeIntegrationTest&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;m_ServerNetworkManager&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;m_ClientNetworkManagers&amp;lt;/code&amp;gt;, ...) is still there for the odd NGO-level check.&lt;br /&gt;
&lt;br /&gt;
=== Pieces you can use on their own ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;&amp;lt;code&amp;gt;FreePort.Udp()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;FreePort.Tcp()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;FreePort.For(transport)&amp;lt;/code&amp;gt;&amp;lt;/strong&amp;gt; — a port free right now (bind to 0, read it back, release it). Serve every test on one of these instead of a fixed port, so parallel runs on one machine (other worktrees, CI jobs, a local server) never collide. For NetworkManagers the NGO harness starts by itself, &amp;lt;code&amp;gt;FreePort.Assign(m_NetworkManagers)&amp;lt;/code&amp;gt; points all their transports at one and returns it.&lt;br /&gt;
* &amp;lt;strong&amp;gt;&amp;lt;code&amp;gt;TestSessions.Create(networkManager)&amp;lt;/code&amp;gt;&amp;lt;/strong&amp;gt; — a &amp;lt;code&amp;gt;NetSession&amp;lt;/code&amp;gt; over a NetworkManager your test made. A game gets its session from &amp;lt;code&amp;gt;NetBootstrap.Session&amp;lt;/code&amp;gt;; the constructor is internal so the runtime API never takes an NGO type ([[Unity.Multiplayer/BIBLE#UM-LAW-2 — Nothing above the NGO adapter imports Unity.Netcode|UM-LAW-2]]), and this assembly, which never ships in a player, is the one public way to build one. &amp;lt;code&amp;gt;TestSessions.ManagerOf(session)&amp;lt;/code&amp;gt; goes the other way.&lt;br /&gt;
* &amp;lt;strong&amp;gt;&amp;lt;code&amp;gt;NetAwait&amp;lt;/code&amp;gt;&amp;lt;/strong&amp;gt; — the waits, as statics with an explicit timeout: &amp;lt;code&amp;gt;Until&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ForSpawn&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ForCopy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ForSynced&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ForTask&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;FindSpawned&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;UntilAsync&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ForSpawnAsync&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ForSyncedAsync&amp;lt;/code&amp;gt; for test code written with &amp;lt;code&amp;gt;async&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;await&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;Awaiting&amp;amp;lt;T&amp;gt;&amp;lt;/code&amp;gt; is what the value-returning waits hand back.&lt;br /&gt;
* &amp;lt;strong&amp;gt;&amp;lt;code&amp;gt;InProcessRendezvousServer&amp;lt;/code&amp;gt;&amp;lt;/strong&amp;gt; — the rendezvous service&amp;#039;s HTTP API served from the test process on a loopback port: the real client, heartbeats and join-by-code without Docker. &amp;lt;code&amp;gt;ForServer(config)&amp;lt;/code&amp;gt; points a server at it (URL and secret; a dedicated server registers itself once running), &amp;lt;code&amp;gt;ForClient(config)&amp;lt;/code&amp;gt; points a client at it; &amp;lt;code&amp;gt;Find(code)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Count&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Heartbeats&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ForgetAll()&amp;lt;/code&amp;gt; (a restarted service) let a test see and disturb it.&lt;br /&gt;
&lt;br /&gt;
=== Join by code in a test ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;public class JoinByCodeTests : NetSessionTest&lt;br /&gt;
{&lt;br /&gt;
    private InProcessRendezvousServer _rendezvous;&lt;br /&gt;
&lt;br /&gt;
    public JoinByCodeTests() : base(Topology.Server, clients: 1) { }&lt;br /&gt;
&lt;br /&gt;
    protected override void OnSessionsCreated() =&amp;gt; _rendezvous = StartRendezvous();&lt;br /&gt;
&lt;br /&gt;
    [UnityTest]&lt;br /&gt;
    public IEnumerator ClientJoinsByTheServersCode()&lt;br /&gt;
    {&lt;br /&gt;
        yield return StartServer(_rendezvous.ForServer(Config()));&lt;br /&gt;
        yield return WaitUntil(() =&amp;gt; !Server.PublishedCode.IsEmpty, &amp;quot;the server never registered&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        var joined = WaitFor(Client.JoinByCode(Server.PublishedCodeText, _rendezvous.ForClient()));&lt;br /&gt;
        yield return joined;&lt;br /&gt;
        Assert.That(joined.Result, Is.True);&lt;br /&gt;
        yield return WaitUntil(() =&amp;gt; Client.State == SessionState.Connected, &amp;quot;the client never connected&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing your front end ===&lt;br /&gt;
&lt;br /&gt;
A game that uses the [[Unity.Multiplayer/articles/front-end|drop-in front end]] tests its menus with &amp;lt;code&amp;gt;Unity.Multiplayer.UI.Testing&amp;lt;/code&amp;gt; (add it to the test assembly&amp;#039;s references beside &amp;lt;code&amp;gt;Unity.Multiplayer.Testing&amp;lt;/code&amp;gt;; it compiles only when MindAttic Components is installed). A batch-mode run is headless, so &amp;lt;code&amp;gt;NetFrontEnd&amp;lt;/code&amp;gt; builds no menus there unless the test asks for them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;[SetUp]    public void SetUp() =&amp;gt; FrontEndTesting.ForceMenus = true;   // before the front end&amp;#039;s Start&lt;br /&gt;
[TearDown] public void TearDown() { FrontEndTesting.ForceMenus = null; FrontEndTesting.CleanUpUi(); }&lt;br /&gt;
&lt;br /&gt;
frontEnd.Identity = new FixedIdentitySource(&amp;quot;Ann&amp;quot;, Color.red);     // never touches PlayerPrefs or the real profile&lt;br /&gt;
FrontEndTesting.Click(FrontEndTesting.MainScreen(frontEnd), &amp;quot;Host&amp;quot;);&lt;br /&gt;
yield return WaitUntil(() =&amp;gt; frontEnd.State == FrontEndState.Lobby, &amp;quot;never reached the lobby&amp;quot;);&lt;br /&gt;
string code = FrontEndTesting.LobbyCode(frontEnd).Code;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;FrontEndTesting&amp;lt;/code&amp;gt; also has &amp;lt;code&amp;gt;Bind(frontEnd, session, config)&amp;lt;/code&amp;gt; (drive a &amp;lt;code&amp;gt;TestSessions.Create&amp;lt;/code&amp;gt; session instead of a NetBootstrap&amp;#039;s), &amp;lt;code&amp;gt;LobbyScreen&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LobbyRoster&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;BusyDialog&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MessageDialog&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Buttons(root)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;HasButton&amp;lt;/code&amp;gt;. A front end beside a real &amp;lt;code&amp;gt;NetBootstrap&amp;lt;/code&amp;gt; needs no &amp;lt;code&amp;gt;Bind&amp;lt;/code&amp;gt;: switch the bootstrap off before its Start (so a headless editor does not serve by itself) and the front end still drives its session.&lt;br /&gt;
&lt;br /&gt;
=== A bad connection ===&lt;br /&gt;
&lt;br /&gt;
Give the clients &amp;lt;code&amp;gt;NetConfig.Conditions&amp;lt;/code&amp;gt; (latency, jitter, loss through Unity Transport&amp;#039;s simulator) in the config you join with, and raise &amp;lt;code&amp;gt;TimeoutSeconds&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;LossyNetworkTests&amp;lt;/code&amp;gt; in the package does exactly that, over the [[Unity.Multiplayer/articles/topologies#Testing a bad connection|lossy profile]].&lt;br /&gt;
&lt;br /&gt;
=== Bots: a server and N bots in one test ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;NetBotTest&amp;lt;/code&amp;gt; is a &amp;lt;code&amp;gt;NetSessionTest&amp;lt;/code&amp;gt; with a dedicated server and one client per bot. Each bot is a &amp;lt;code&amp;gt;NetBotRunner&amp;lt;/code&amp;gt; that joins by the join code the server writes to a file, through an in-process rendezvous service, and then hands its session to your &amp;lt;code&amp;gt;IBotDriver&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;RunBots(role =&amp;gt; new MyBot(), &amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;)&amp;lt;/code&amp;gt; fails the test unless every bot passes. This is the nightly compose smoke without Docker; see [[Unity.Multiplayer/articles/bots#In-process tests: NetBotTest|Bots and end-to-end smoke tests]].&lt;br /&gt;
&lt;br /&gt;
=== Examples to copy ===&lt;br /&gt;
&lt;br /&gt;
* A game made with &amp;lt;strong&amp;gt;MindAttic ▸ Multiplayer ▸ New Game…&amp;lt;/strong&amp;gt; starts with both kinds. &amp;lt;code&amp;gt;Tests/PlayMode/GameTests.cs&amp;lt;/code&amp;gt; has &amp;lt;code&amp;gt;PlayerTests&amp;lt;/code&amp;gt; (a &amp;lt;code&amp;gt;[ToServer]&amp;lt;/code&amp;gt; round trip, roster name and colour, server-side clamping), &amp;lt;code&amp;gt;CrateTests&amp;lt;/code&amp;gt; (objects by key, a restart vote through &amp;lt;code&amp;gt;VoteBoard&amp;lt;/code&amp;gt;) and &amp;lt;code&amp;gt;BotTests&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;NetBotTest&amp;lt;/code&amp;gt;). &amp;lt;code&amp;gt;Tests/EditMode/GameSetupTests.cs&amp;lt;/code&amp;gt; checks the scene&amp;#039;s kit components and runs the prefab validator. Its asmdefs are the ones above. &amp;lt;code&amp;gt;tests/run-new-game.ps1&amp;lt;/code&amp;gt; runs them in a brand-new project.&lt;br /&gt;
* &amp;lt;code&amp;gt;tests/MinimalSample/Tests&amp;lt;/code&amp;gt; — the Minimal sample&amp;#039;s player prefab tested as a game would: &amp;lt;code&amp;gt;SetPlayerPrefab&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;StartAndJoinAll&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;WaitForSpawn&amp;lt;/code&amp;gt; for each peer&amp;#039;s player, &amp;lt;code&amp;gt;WaitUntil&amp;lt;/code&amp;gt; on synced positions and RPCs.&lt;br /&gt;
* The package&amp;#039;s own suites under &amp;lt;code&amp;gt;unity/com.mindattic.unity.multiplayer/Tests/Runtime&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;HostAndClientTests&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ServerAndClientsTests&amp;lt;/code&amp;gt; (both topologies, both transports), &amp;lt;code&amp;gt;EntityRpcTests&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApprovalAndSeatTests&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;JoinByCodeTests&amp;lt;/code&amp;gt; (the rendezvous helper), &amp;lt;code&amp;gt;LossyNetworkTests&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NetBotTests&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;NetBotTest&amp;lt;/code&amp;gt;: two bots join by code and get an RPC answered), and &amp;lt;code&amp;gt;TestKitTests&amp;lt;/code&amp;gt; (the kit&amp;#039;s own guarantees).&lt;br /&gt;
* Unity.Cursory&amp;#039;s PlayMode suite, the first game built on the package.&lt;br /&gt;
&lt;br /&gt;
== The package&amp;#039;s own suites ==&lt;br /&gt;
&lt;br /&gt;
The package is tested at two levels: plain &amp;lt;code&amp;gt;dotnet test&amp;lt;/code&amp;gt; for everything engine-free, and Unity PlayMode/EditMode suites for everything that needs the engine or real networking. Both run in CI (&amp;lt;code&amp;gt;.github/workflows/ci.yml&amp;lt;/code&amp;gt;); a nightly job additionally runs a real two-client smoke test end to end.&lt;br /&gt;
&lt;br /&gt;
=== dotnet test ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-bash&amp;quot;&amp;gt;dotnet test tests/Core.Tests          # Unity.Multiplayer.Core: config, join codes, seats, approval, rpc gate, rendezvous client...&lt;br /&gt;
dotnet test tests/Rendezvous.Tests    # server/Rendezvous, hosted in-process with WebApplicationFactory&lt;br /&gt;
dotnet test tests/Generators.Tests    # the source generator and its analyzer diagnostics&lt;br /&gt;
dotnet test tests/Hosting.Cli.Tests   # mp-host: every provisioner/allocator call mocked&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No Unity install is needed for any of these. &amp;lt;code&amp;gt;Unity.Multiplayer.Core&amp;lt;/code&amp;gt; is engine-free by design (&amp;lt;code&amp;gt;UM-LAW-2&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;noEngineReferences&amp;lt;/code&amp;gt;): &amp;lt;code&amp;gt;tests/Core.Tests&amp;lt;/code&amp;gt; compiles the package&amp;#039;s own &amp;lt;code&amp;gt;Runtime/Core/**/*.cs&amp;lt;/code&amp;gt; straight in (&amp;lt;code&amp;gt;&amp;amp;lt;Compile Include=&amp;quot;..\..\unity\...\Runtime\Core\**\*.cs&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;), so the code under test is exactly the code Unity imports, not a copy. &amp;lt;code&amp;gt;tests/Core.Build&amp;lt;/code&amp;gt; compiles the same sources as netstandard2.1 / C# 9 — the way Unity actually compiles them — so a language feature Core.Tests&amp;#039; net10 TFM would silently allow still fails the way it would in Unity.&lt;br /&gt;
&lt;br /&gt;
==== Generators.Tests ====&lt;br /&gt;
&lt;br /&gt;
Snapshot-tests the generator&amp;#039;s output: the package&amp;#039;s own &amp;lt;code&amp;gt;TestAvatar&amp;lt;/code&amp;gt; and one test per member shape (every RPC direction, every &amp;lt;code&amp;gt;[Synced]&amp;lt;/code&amp;gt; type), each compiled clean as C# 9. One test per diagnostic in [[Unity.Multiplayer/articles/attributes#Generator diagnostics|Attributes reference]] asserts it fires for the broken input it&amp;#039;s meant to catch. After an intentional change to the generator&amp;#039;s output shape:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-bash&amp;quot;&amp;gt;UPDATE_SNAPSHOTS=1 dotnet test tests/Generators.Tests&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
rewrites &amp;lt;code&amp;gt;Snapshots/&amp;lt;/code&amp;gt; — review the diff before committing it, since it&amp;#039;s the thing the test is meant to pin.&lt;br /&gt;
&lt;br /&gt;
==== Hosting.Cli.Tests ====&lt;br /&gt;
&lt;br /&gt;
Every &amp;lt;code&amp;gt;mp-host&amp;lt;/code&amp;gt; provider call (Hetzner, Vultr, DigitalOcean, AWS, GCE, Azure, Fly, RunPod, Edgegap, Gameye, GameLift, ...) is mocked with NUnit, so this suite runs with no cloud credentials and touches no real API. Each provider also has opt-in &amp;lt;code&amp;gt;[Explicit]&amp;lt;/code&amp;gt; smoke tests that exercise the real API and always tear down what they create — run those only with real credentials loaded (&amp;lt;code&amp;gt;mp-host credentials set-...&amp;lt;/code&amp;gt;), never in CI. See [[Unity.Multiplayer/articles/hosting#Secrets|Hosting]] for where those credentials live.&lt;br /&gt;
&lt;br /&gt;
=== Unity suites ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-powershell&amp;quot;&amp;gt;powershell -File tests/run-playmode.ps1     # PlayMode: the test kit&amp;#039;s fixture over real Unity Transport, loopback&lt;br /&gt;
powershell -File tests/run-editmode.ps1     # EditMode: editor tooling, one real Linux server build (-SkipBuild to leave it out)&lt;br /&gt;
powershell -File tests/run-sample.ps1       # imports the Minimal sample through Package Manager, runs its PlayMode tests&lt;br /&gt;
powershell -File tests/run-sample.ps1 -Sample FrontEnd   # the same for the Front End sample&lt;br /&gt;
powershell -File tests/run-smoke.ps1        # builds the nightly smoke test&amp;#039;s Linux player&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These need Unity 6000.4.3f1 installed locally (&amp;lt;code&amp;gt;tests/PlayModeHost&amp;lt;/code&amp;gt; is the bare project both suites run against). The host also references MindAttic Components and Unity.Shared by &amp;lt;code&amp;gt;file:&amp;lt;/code&amp;gt; path, as sibling repos of this one, so the optional front end compiles and its PlayMode suite (&amp;lt;code&amp;gt;Unity.Multiplayer.UI.Tests&amp;lt;/code&amp;gt;) runs beside the main one; &amp;lt;code&amp;gt;tests/prepare-host.ps1&amp;lt;/code&amp;gt;, called by both scripts, imports TextMesh Pro&amp;#039;s Essential Resources on a clean checkout first. PlayMode suites cover what only means something with real networking: hosting and joining over UDP and WebSocket, reconnect taking back the same seat, a killed client&amp;#039;s restart taking over a stale connection, scene flow and late joiners, every RPC direction and rate limiting, join codes against the in-process rendezvous service, the whole flow again under [[Unity.Multiplayer/articles/topologies#Testing a bad connection|simulated latency and loss]] (&amp;lt;code&amp;gt;LossyNetworkTests&amp;lt;/code&amp;gt;), and the [[Unity.Multiplayer/articles/front-end#Where it is tested|drop-in front end]] driven through its menus. Every suite serves on a free port, so several runs can share a machine. EditMode covers the setup wizard, the prefab validator and the dedicated-server build — including a real Mono Linux build inside the suite, skipped only in CI (GameCI&amp;#039;s editor image has no Linux Dedicated Server build-support module) and still run by &amp;lt;code&amp;gt;run-editmode.ps1&amp;lt;/code&amp;gt; locally, per HOUSE-LAW-8 (done is verified, not asserted).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;run-sample.ps1&amp;lt;/code&amp;gt; builds a throwaway host project (&amp;lt;code&amp;gt;tests/SampleHost&amp;lt;/code&amp;gt;, git-ignored), imports the Minimal sample through &amp;lt;code&amp;gt;UnityEditor.PackageManager.UI.Sample&amp;lt;/code&amp;gt; the same way a game developer would from the Package Manager window, and runs &amp;lt;code&amp;gt;tests/MinimalSample/Tests&amp;lt;/code&amp;gt; against the imported copy — so the sample that ships is the sample that&amp;#039;s tested, not a copy kept in sync by hand. Its manifest lists only NGO as testable, as a game&amp;#039;s does, so it also proves the test kit compiles for a consumer. &amp;lt;code&amp;gt;-Author&amp;lt;/code&amp;gt; regenerates its scene, prefab and prefab list.&lt;br /&gt;
&lt;br /&gt;
=== The nightly smoke test ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;.github/workflows/nightly-smoke.yml&amp;lt;/code&amp;gt; builds one Linux player (&amp;lt;code&amp;gt;tests/MinimalSample/Editor/SmokeHostBuild.cs&amp;lt;/code&amp;gt;) that plays every role — rendezvous service, dedicated server, or bot client — picked at run time by the &amp;lt;code&amp;gt;MINDATTIC_ROLE&amp;lt;/code&amp;gt; environment variable (&amp;lt;code&amp;gt;tests/MinimalSample/Runtime/SmokeDriver.cs&amp;lt;/code&amp;gt;), and runs all three under Docker Compose (&amp;lt;code&amp;gt;smoke/docker-compose.yml&amp;lt;/code&amp;gt;). The server registers with rendezvous and publishes a join code to a shared volume; two bot clients read it, join through the rendezvous service, and drive their squares into the arena wall. &amp;lt;code&amp;gt;smoke/wait-for-smoke.sh&amp;lt;/code&amp;gt; watches for both bots&amp;#039; &amp;lt;code&amp;gt;OK:&amp;lt;/code&amp;gt; log lines. This is the one test that proves the join-code flow and an RPC round trip end to end, against the actual built player, not a PlayMode stand-in. Run it locally with &amp;lt;code&amp;gt;powershell -File tests/run-smoke.ps1&amp;lt;/code&amp;gt;. A game gets the same smoke with no code of its own from &amp;lt;code&amp;gt;mp-host game smoke&amp;lt;/code&amp;gt; and the reusable &amp;lt;code&amp;gt;game-smoke.yml&amp;lt;/code&amp;gt; workflow ([[Unity.Multiplayer/articles/bots|Bots]]).&lt;br /&gt;
&lt;br /&gt;
=== CI ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;.github/workflows/ci.yml&amp;lt;/code&amp;gt; runs the four &amp;lt;code&amp;gt;dotnet test&amp;lt;/code&amp;gt; suites above as a matrix job, plus GameCI&amp;#039;s &amp;lt;code&amp;gt;unity-test-runner&amp;lt;/code&amp;gt; for EditMode and PlayMode (&amp;lt;code&amp;gt;-runTests -batchmode&amp;lt;/code&amp;gt;, filtered to one test assembly per mode). Both Unity jobs need a &amp;lt;code&amp;gt;UNITY_LICENSE&amp;lt;/code&amp;gt; repository secret; &amp;lt;code&amp;gt;tools/set-ci-secrets.ps1&amp;lt;/code&amp;gt; sets it (see [[Unity.Multiplayer/articles/ci-secrets|CI secrets]]). &amp;lt;code&amp;gt;.github/workflows/docs.yml&amp;lt;/code&amp;gt; (this site) and &amp;lt;code&amp;gt;.github/workflows/nightly-smoke.yml&amp;lt;/code&amp;gt; are separate workflows — see [[Unity.Multiplayer/articles/hosting|Hosting]] for what the smoke test proves about a real deploy, and the repository root &amp;lt;code&amp;gt;README.md&amp;lt;/code&amp;gt; for the exact commands.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;md2wiki-crumb&amp;quot;&amp;gt;Part of [[Unity.Multiplayer]].&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;md2wiki-source&amp;quot;&amp;gt;From [https://github.com/mindattic/Unity.Multiplayer/blob/main/docs/articles/testing.md Unity.Multiplayer/docs/articles/testing.md] via MindAttic.Docs; synced automatically, so edit the repo, not this page.&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Unity.Multiplayer]]&lt;/div&gt;</summary>
		<author><name>Docs Sync</name></author>
	</entry>
</feed>