{!See https://docs.google.com/document/d/1takg_GmIBBKKTj-GHZCwzxohpQz7Bhekivkk72kYMtE/edit for reference implementation of OneTrust, dataLayer and GTM} {!OneTrust Cookies Consent} {!OneTrust Cookies Consent end} {!dataLayer initialization push} {!dataLayer initialization push end} {!Google Tag Manager} {!Google Tag Manager end} Edit Mode vs. Play Mode tests | Test Framework | 1.0.18
docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Edit Mode vs. Play Mode tests

    Let’s clarify a bit what Play Mode and Edit Mode test means from the Unity Test Framework perspective:

    Edit Mode tests

    Edit Mode tests (also known as Editor tests) are only run in the Unity Editor and have access to the Editor code.

    With Edit Mode tests you may want to test any of your Editor extensions using the UnityTest attribute. In this case, your test code runs in the EditorApplication.update callback loop.

    Note: You can also control entering and exiting Play Mode from your Edit Mode test.

    Edit Mode tests should meet one of the following conditions:

    • They should have an assembly definition file, that references NUnit and has only the Editor as a target platform:
        "includePlatforms": [
            "Editor"
        ],
    
    • Legacy condition: put tests in the project’s Editor folder.

    Play Mode tests

    You can run Play Mode tests as a standalone in a Player or inside the Editor. Play Mode tests allow you to exercise your game code, as the tests run as coroutines if marked with the UnityTest attribute.

    Play Mode tests should correspond to the following conditions:

    • Have an assembly definition with reference to nunit.framework.dll.
    • Have the test scripts located in a folder with the .asmdef file.
    • The test assembly should reference an assembly within the code that you need to test.
        "references": [
            "NewAssembly"
        ],
        "optionalUnityReferences": [
            "TestAssemblies"
       ],
        "includePlatforms": [],
    

    Recommendations

    Attributes

    Use the NUnit Test attribute instead of the UnityTest attribute, unless you need to yield special instructions, in Edit Mode, or if you need to skip a frame or wait for a certain amount of time in Play Mode.

    References

    Reference in your tests UnityEngine.TestRunner and UnityEditor.TestRunner, only Edit Mode tests requires the latter. The TestAssemblies option under optionalUnityReference is auto-updated into a reference to the NUnit and TestRunner assemblies.

    In This Article
    Back to top
    Copyright © 2023 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)