Search Unity

Unity3D Tests - Edit Mode vs Test Mode

Discussion in 'General Discussion' started by zaheerali43958, Dec 14, 2021.

  1. zaheerali43958

    zaheerali43958

    Joined:
    Dec 14, 2021
    Posts:
    3
    I have been reading about Edit Mode vs Play Mode testing and I'm not seeing any real reasons of why I would use Play mode testing over Edit mode testing. My assumption is that edit mode is better for writing tests and play mode is more for when testing is finalized.

    What might sway someone to use one mode over the other? Source

    ** EDIT **

    I'm finding out that

    • UnityEngine.SceneManagement only works in Play Mode
    • Play Mode tests seem to always run even on editor play button
    • Editor tests seem to only run on manual test run
     
    Last edited: Jan 3, 2022
  2. sxa

    sxa

    Joined:
    Aug 8, 2014
    Posts:
    741
    You've not said what you're trying to test.

    But if you're testing your game or application, why would you use Edit Mode, geared towards testing Editor extensions running inside Unity, instead of Play Mode, geared towards testing games and applications that run separately.

    If you're building and testing Editor extensions, obviously that's the use case for Edit mode.
     
    Joe-Censored likes this.
  3. zaheerali43958

    zaheerali43958

    Joined:
    Dec 14, 2021
    Posts:
    3
    I'm finding out that
    • UnityEngine.SceneManagement only works in Play Mode
    • Edit Mode tests seem to only run from the Test Runner directly
    Biggest take-aways
    • Play Mode testing seems most beneficial and accurate to UX
    • Edit Mode seems to be for pre-commit style testing eg. run smoke tests whenever the editor is modified
    My favorite article on Unity game testing is by Ray Wenderlich

    Better Answer
    Use EditMode tests for Unit tests.

    • Unit Testing
    • Integration Testing
    • Functional Testing
    Edit Mode is out-of-game so it works great for quick testing. Especially if your game is really big then edit mode keeps you from losing compile time over and over again while still being able to make sure your building blocks are intact.

    Use PlayMode tests for
    • End-to-End Testing
    • Acceptance Testing
    • Performance Testing
    • Smoke Testing
    With Play Mode you're in game and are really capturing the user's experience in your tests. On a small interactive you really could put all your tests here.

    All in all, learn the various testing types then mix-and-match to what works best for your specific application.

    My favorite "quick" article on various testing types

    Additionally

    If your unity project is part of a continuous integration project (cicd) then you can use headless unity with unlocked fps as part of your validation.