.. | |||
Editor | 6 years ago | ||
Input | 6 years ago | ||
Utilities | 6 years ago | ||
Editor.meta | 6 years ago | ||
Input.meta | 6 years ago | ||
README.md | 6 years ago | ||
README.md.meta | 6 years ago | ||
Utilities.meta | 6 years ago |
This folder will host unit tests that test individual HoloToolkit-Unity components.
Since MonoBehaviours are highly coupled to the Unity Engine there are some details one has to know when testing them.
This means any objects from the original scene will still exist next to the test scene and may interfere with your tests. For example if a tests creates a main camera and tries to use it, it may find the main camera of the original scene instead. Furthermore unity will not clear the scene between each test so objects created in other tests might interfere as well.
Clear the scene if required by using TestUtils.ClearScene()
, either manually at the start of the test or define a SetUp
method that calls it.
[SetUp] public void ClearScene() { TestUtils.ClearScene(); } `
Awake
, Start
and Update
will not be called by Unity in tests.As the name editor test implies they are only executed in the editor and as such instantiated objects do not get the usual events. The TestUtils
provide a way to simulate some of the behaviour by manually calling the required methods. It is obviously not the goal to recreate the whole Unity Engine by manually calling dozens of methods on an object. The logic in scripts should be seperated enough so that the tests remain small.
[Test] public void CallAwakeTest() { var gameObject = new GameObject(); var reflectionTest = gameObject.AddComponent<ReflectionTestBehaviour>(); gameObject.CallAwake(); Assert.That(reflectionTest.AwakeCalled, Is.True); }
Null checks with classes like GameObject
, Transform
and others will behave differently when checked against with Is.Null
and Is.Not.Null
. The reason for this is that a destroyed unity Object
cast to object
and compared against null returns false, as the Object
still exists and is marked as destroyed.
For this we provide a custom constraint that captures this behaviour and returns the expected results. Is.UnityNull
and Is.Not.UnityNull()
which also works with the default behaviour so that any object can compared against it, not just Unity ones.
[Test] public void TestGameObjectUnityNull() { var gameObject = new GameObject(); Object.DestroyImmediate(gameObject); Assert.That(gameObject, Is.UnityNull); } [Test] public void TestGameObjectNotUnityNull() { Assert.That(new GameObject(), Is.Not.UnityNull()); }