Skip to content

Instantly share code, notes, and snippets.

@makihiro
Last active January 14, 2021 04:11
Show Gist options
  • Save makihiro/199c8fa7047b980501c98ae8d69ec235 to your computer and use it in GitHub Desktop.
Save makihiro/199c8fa7047b980501c98ae8d69ec235 to your computer and use it in GitHub Desktop.
ARTest-TestARSpawn.cs
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.SceneManagement;
using Assert = UnityEngine.Assertions.Assert;
// Test AR behavior with Unity Test Framework
namespace Tests
{
public class TestARSpawn
{
public GameObject[] obj;
[SetUp]
public void Init()
{
SceneManager.LoadScene("SimpleAR");
}
// Test for AR object spawn
[UnityTest]
public IEnumerator TestARSpawnWithEnumeratorPasses()
{
float time = 0;
while (time < 10)
{
obj = GameObject.FindGameObjectsWithTag("ar1");
time += Time.fixedDeltaTime;
yield return new WaitForFixedUpdate();
}
Assert.AreNotEqual(obj.Length, 0);
}
// Test for AR object size fit
[UnityTest]
public IEnumerator TestARObjectSizePasses()
{
float time = 0;
while (time < 10)
{
obj = GameObject.FindGameObjectsWithTag("ar1");
time += Time.fixedDeltaTime;
yield return new WaitForFixedUpdate();
}
var size = obj[0].transform.localScale;
Assert.AreApproximatelyEqual(1.2f, size.x, 0.2f);
Assert.AreApproximatelyEqual(1.2f, size.y, 0.2f);
Assert.AreApproximatelyEqual(1.2f, size.z, 0.2f);
}
// Test for AR object rotation
[UnityTest]
public IEnumerator TestARObjectRotationPasses()
{
float time = 0;
while (time < 10)
{
obj = GameObject.FindGameObjectsWithTag("ar1");
time += Time.fixedDeltaTime;
yield return new WaitForFixedUpdate();
}
var quaternion = obj[0].transform.rotation;
Quaternion expected = new Quaternion(0.0f, 1.0f, 0.0f, 0.1f);
Assert.AreApproximatelyEqual(expected.x, quaternion.x, 0.1f);
Assert.AreApproximatelyEqual(expected.y, quaternion.y, 0.1f);
Assert.AreApproximatelyEqual(expected.z, quaternion.z, 0.1f);
Assert.AreApproximatelyEqual(expected.w, quaternion.w, 0.1f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment