-
Notifications
You must be signed in to change notification settings - Fork 557
feat: test utilities script including Playmode test helpers #484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
9206577
bc95fe5
82f0dd6
40808d2
bce3f8a
07cfb79
019f19c
488db79
cb5c780
148821d
c4d0580
4509df0
aafded5
31d7ca0
f3c963e
115b538
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "Unity.Multiplayer.Samples.Coop.Tests.Editor", | ||
"rootNamespace": "", | ||
"references": [ | ||
"UnityEngine.TestRunner", | ||
"UnityEditor.TestRunner" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": true, | ||
"precompiledReferences": [ | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": false, | ||
"defineConstraints": [ | ||
"UNITY_INCLUDE_TESTS" | ||
], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "Unity.Multiplayer.Samples.Coop.Tests.Runtime", | ||
"rootNamespace": "", | ||
"references": [ | ||
"UnityEngine.TestRunner", | ||
"UnityEditor.TestRunner" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": true, | ||
"precompiledReferences": [ | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": false, | ||
"defineConstraints": [ | ||
"UNITY_INCLUDE_TESTS" | ||
], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System.Collections; | ||
using UnityEngine; | ||
using NUnit.Framework; | ||
using UnityEngine.EventSystems; | ||
using UnityEngine.SceneManagement; | ||
using UnityEngine.UI; | ||
|
||
namespace Unity.Multiplayer.Samples.Utilities | ||
{ | ||
public abstract class TestUtils | ||
{ | ||
/// <summary> | ||
/// Finds an active Button GameObject by name. If Button component is present on GameObject, it will be clicked. | ||
/// </summary> | ||
/// <param name="name"> Name of Button GameObject </param> | ||
public static void ClickButtonByName(string name) | ||
{ | ||
var buttonGameObject = GameObject.Find(name); | ||
|
||
Assert.IsNotNull(buttonGameObject, | ||
$"Button GameObject with name {name} not found in scene!"); | ||
|
||
EventSystem.current.SetSelectedGameObject(buttonGameObject); | ||
|
||
var buttonComponent = buttonGameObject.GetComponent<Button>(); | ||
|
||
Assert.IsNotNull(buttonComponent, $"Button component not found on {buttonGameObject.name}!"); | ||
|
||
buttonComponent.onClick.Invoke(); | ||
} | ||
|
||
/// <summary> | ||
/// Helper wrapper method for asserting the completion of a scene load to be used inside Playmode tests. A scene | ||
/// is either loaded successfully, or the loading process has timed out. | ||
/// </summary> | ||
/// <param name="sceneName"> Name of scene </param> | ||
/// <returns></returns> | ||
public static IEnumerator AssertIsSceneLoaded(string sceneName) | ||
{ | ||
var waitUntilSceneLoaded = new WaitForSceneLoad(sceneName); | ||
|
||
yield return waitUntilSceneLoaded; | ||
|
||
Assert.That(!waitUntilSceneLoaded.timedOut); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Custom IEnumerator class to validate the loading of a Scene by name. If a scene load lasts longer than | ||
/// k_MaxSceneLoadDuration it is considered a timeout. | ||
/// </summary> | ||
public class WaitForSceneLoad : CustomYieldInstruction | ||
{ | ||
const float k_MaxSceneLoadDuration = 10f; | ||
|
||
string m_SceneName; | ||
|
||
float m_LoadSceneStart; | ||
|
||
float m_MaxLoadDuration; | ||
|
||
public bool timedOut { get; private set; } | ||
LPLafontaineB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public override bool keepWaiting | ||
{ | ||
get | ||
{ | ||
var scene = SceneManager.GetSceneByName(m_SceneName); | ||
|
||
var isSceneLoaded = scene.IsValid() && scene.isLoaded; | ||
|
||
if (Time.time - m_LoadSceneStart >= m_MaxLoadDuration) | ||
{ | ||
timedOut = true; | ||
} | ||
|
||
return !isSceneLoaded && !timedOut; | ||
} | ||
} | ||
|
||
public WaitForSceneLoad(string sceneName, float maxLoadDuration = k_MaxSceneLoadDuration) | ||
{ | ||
m_LoadSceneStart = Time.time; | ||
m_SceneName = sceneName; | ||
m_MaxLoadDuration = maxLoadDuration; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "Unity.Multiplayer.Samples.Utilities.Testing", | ||
"rootNamespace": "", | ||
"references": [], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": true, | ||
"precompiledReferences": [ | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.