Unity: What's the difference between a PlayMode UnityTest and an EditMode UnityTest?

Viewed 2149

I'm trying to learn how to write tests in Unity3D, but the documentation is sparse.

You can use [UnityTest] on both PlayMode or EditMode tests, but I don't understand the significance in choosing one over the other. I think in PlayMode, it actually runs your game, but I still don't understand why I would or would not want that.

1 Answers

It is actually quite simple:

EditMode:

Check anything that doesn't require PlayMode (Update, Awake, Start etc) or that has to be tested explicitly before entering it e.g.

  • is there a Camera in the Scene?
  • for mixed reality: is the Camera at position 0, 0, 0 before the playmode starts?
  • does the Camera have a PhysicsRaycaster component to make IPointerXxx interfaces work

or also the functionality of custom editor scripts.

For some it is necessary to test them before entering PlayMode, for the rest this method is simply faster since it doesn't have to initialize everything in your Scene before being able to test one specific thing.

PlayMode:

Check scripts that require runtime (Update, FixedUpdate, etc), everything initialized (executed Awake, Start, etc) or physics e.g.

  • will this object have all components initialized before accessing them?
  • will this while loop terminate (within a given time)?
  • the best physics example I saw was about Physics materials: If bounciness is set to 0.99 will the ball stop jumping after X seconds?
Related