Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace Tests
{
public class AutoSyncTransformテスト
{
[Test]
[Order(0)]
public void 生成直後()
{
var obj = new GameObject("target", typeof(BoxCollider));
obj.transform.position = new Vector3(0, 0, 3);
RaycastHit hit;
var result = Physics.Raycast(Vector3.zero, new Vector3(0, 0, 10), out hit);
Object.DestroyImmediate(obj);
Assert.IsTrue(result, "生成が反映されていない");
Assert.AreEqual(2.5f, hit.distance, "距離が正しくない、もしくはColliderのゴミが残ってる");
}
[Test]
[Order(1)]
public void 生成しない()
{
RaycastHit hit;
var result = Physics.Raycast(Vector3.zero, new Vector3(0, 0, 10), out hit);
Assert.IsFalse(result, "何らかのゴミが残ってる");
}
[Order(2)]
[UnityTest]
public IEnumerator 生成直後_UnityTest版()
{
yield return null;
//yield return new WaitForFixedUpdate();
RaycastHit hit1, hit2;
var result1 = Physics.Raycast(Vector3.zero, new Vector3(0, 0, 10), out hit1);
var obj = new GameObject("target", typeof(BoxCollider));
obj.transform.position = new Vector3(0, 0, 10);
var result2 = Physics.Raycast(Vector3.zero, new Vector3(0, 0, 10), out hit2);
Object.DestroyImmediate(obj);
Assert.IsFalse(result1, "Colliderのゴミが残ってる");
Assert.IsTrue(result2, "生成が反映されていない");
Assert.AreEqual(9.5f, hit2.distance, "変更が反映されていない");
}
[Order(3)]
[UnityTest]
public IEnumerator 生成後1フレーム待つ()
{
RaycastHit hit1, hit2;
var result1 = Physics.Raycast(Vector3.zero, new Vector3(0, 0, 10), out hit1);
var obj = new GameObject("target", typeof(BoxCollider));
obj.transform.position = new Vector3(0, 0, 5);
yield return null;
//yield return new WaitForFixedUpdate();
var result2 = Physics.Raycast(Vector3.zero, new Vector3(0, 0, 10), out hit2);
Object.DestroyImmediate(obj);
Assert.IsFalse(result1, "Colliderのゴミが残ってる");
Assert.IsTrue(result2, "生成が反映されていない");
Assert.AreEqual(4.5f, hit2.distance, "変更が反映されていない");
}
[Order(3)]
[UnityTest]
public IEnumerator 動かした直後の動作()
{
RaycastHit hit1, hit2;
var result1 = Physics.Raycast(Vector3.zero, new Vector3(0, 0, 10), out hit1);
var obj = new GameObject("target", typeof(BoxCollider));
obj.transform.position = new Vector3(0, 0, 10);
yield return null;
//yield return new WaitForFixedUpdate();
obj.transform.position = new Vector3(0f, 0f, 5f);
var result2 = Physics.Raycast(Vector3.zero, new Vector3(0, 0, 10), out hit2);
Object.DestroyImmediate(obj);
Assert.IsFalse(result1, "Colliderのゴミが残ってる");
Assert.IsTrue(result2, "生成が反映されていない");
Assert.AreEqual(4.5f, hit2.distance, "変更が反映されていない");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment