Created
February 8, 2016 16:00
-
-
Save jagwire/35401ab6d74623ed9360 to your computer and use it in GitHub Desktop.
Automatic Testing Scenario in Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MHS { | |
interface ISpinner { | |
public void spin(Vector3 value); | |
} | |
[Serializable] | |
public SpinController { //we can instantiate this in a test | |
public float speed; | |
public Vector3 axis; | |
private ISpinner spinner; | |
public void setSpinController(ISpinController spinner) { | |
this.spinner = spinner; | |
} | |
public void doStuffBasedOnTime(float time) { | |
spinner.spin(time); | |
} | |
} | |
public Spinner : GameBehavior, ISpinner { // we cannot instantiate this in a test | |
public SpinController controller; | |
void OnEnable() { | |
controller.SetSpinController(this); | |
} | |
void Update() { | |
controller.doStuffBasedOnTime(Time.deltaTime); | |
} | |
//ISpinner implementation: | |
public void spin(Vector3 value) { | |
transform.Rotate(value); | |
} | |
} | |
} | |
namespace MHS.Tests { | |
[TestFixture] | |
public class SpinnerTest { | |
} | |
[Test] | |
public void objectSpinsBasedOnTimeAndAxis() { | |
//arrange | |
SpinController controller = ...; | |
ISpinner spinner = ...; | |
controller.speed = 5f; | |
controller.axis = new Vector3(0,1,0); | |
controller.SetSpinner(spinner); | |
//act | |
controller.doStuffBasedOnTime(0.02f); | |
//assert | |
Assert.AreEqual(spinner.rotation, controller.axis*controller.speed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment