@@ -57,6 +57,7 @@ due to their level of complexity.
57
57
* AnimatorPlayback objects to easily detect animation completion conditions
58
58
* Pre-built library on AnimatorBehavior(s) for complex animation playback
59
59
* Animator extensions that add missing functionality to Unity's Animator component
60
+ * Animator unit testing helper (for editor only tests)
60
61
* Unit tested
61
62
62
63
#### Requesting Features
@@ -125,3 +126,42 @@ call per unique `AnimatorController`. While this generally shouldn't cause perfo
125
126
You may need to call ` AnimatorHelperRuntime.Instance.Cache(Animator) ` on ` Start ` or ` Awake ` if your ` Animator(s) `
126
127
have over 300 parameters. Please note that your ` AnimatorController ` object (what you pass into the Animator via
127
128
inspector) must be uniquely named in order for the caching to work correctly.
129
+
130
+ ## Animator Unit Test Helper
131
+
132
+ This library provides an ` AnimatorStub ` (editor only) class that makes testing animations via pure code super simple.
133
+ All you need to do is the following.
134
+
135
+ ``` c#
136
+ using Adnc .AnimatorHelpers .Editors .Testing .Utilities ;
137
+ using NUnit .Framework ;
138
+ using UnityEngine ;
139
+
140
+ public class TestAnimatorStub {
141
+ private AnimatorStub _stub ;
142
+
143
+ [SetUp ]
144
+ public void Setup () {
145
+ _stub = new AnimatorStub ();
146
+ }
147
+
148
+ [TearDown ]
149
+ public void Teardown () {
150
+ // The stub is attached to a GameObject, so it must be destroyed manually
151
+ Object .DestroyImmediate (_stub .Animator .gameObject );
152
+ }
153
+
154
+ [Test ]
155
+ public void MyTest () {
156
+ // Setup your AnimatorController as desired
157
+ stub .AnimatorCtrl .AddParameter (" myBool" , AnimatorControllerParameterType .Bool );
158
+
159
+ // Inject a runtime version of the AnimatorController with all of your settings
160
+ stub .InjectCtrl ();
161
+
162
+ // Test as normal
163
+ // stub.Animator.Update(10); // If you need to simulate time
164
+ Assert .IsTrue (stub .Animator .HasBool (" myBool));
165
+ }
166
+ }
167
+ ```
0 commit comments