Added basic edit mode test

This commit is contained in:
Jason Durand 01 2022-04-12 20:44:59 -04:00
parent 3abe9a46dd
commit 60b2e598c8
6 changed files with 58 additions and 27 deletions

View File

@ -1,6 +1,5 @@
#nullable enable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

View File

@ -0,0 +1,20 @@
{
"name": "Ludum50",
"rootNamespace": "",
"references": [
"GUID:776d03a35f1b52c4a9aed9f56d7b4229",
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:4307f53044263cf4b835bd812fc161a4",
"GUID:df380645f10b7bc4b97d4f5eb6303d95"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ff1917848eda86b469287c353bf3cba7
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -161,8 +161,8 @@ public class PlayerMovement : MonoBehaviour {
#region States
void SwitchState(BaseState newState) {
currentState.LeaveState();
public void SwitchState(BaseState newState) {
currentState?.LeaveState();
currentState = newState;
newState.EnterState();
}

View File

@ -1,9 +1,24 @@
{
"name": "EditMode",
"optionalUnityReferences": [
"TestAssemblies"
"rootNamespace": "",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"Ludum50"
],
"includePlatforms": [
"Editor"
]
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -1,25 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
public class EditMode
{
// A Test behaves as an ordinary method
[Test]
public void EditModeSimplePasses()
{
// Use the Assert class to test conditions
}
public class EditMode {
[Test]
public void SwitchStateTest() {
var gameObject = new GameObject();
var playerMovement = gameObject.AddComponent<PlayerMovement>();
playerMovement.SwitchState(new TestState());
Assert.True(playerMovement.currentState is TestState);
}
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
// `yield return null;` to skip a frame.
[UnityTest]
public IEnumerator EditModeWithEnumeratorPasses()
{
// Use the Assert class to test conditions.
// Use yield to skip a frame.
yield return null;
}
}
class TestState : BaseState {}
}