Search Unity

Enable Playmode Tests for All Assemblies option missing

Discussion in 'Testing & Automation' started by KaPow1, Mar 19, 2021.

  1. KaPow1

    KaPow1

    Joined:
    Jan 27, 2013
    Posts:
    9
    I'm fairly new to unit testing but am trying to write a new playmode test. I'm working in a large codebase that hasn't been using assembly definitions up to this point, and we don't want to introduce assembly definitions at this time.

    I understand that you should be able to run playmode tests on all assemblies (I assume even Assembly-CSharp) if you "enable playmode tests for all assemblies". In the manual on playmode tests it mentions enabling tests for all assemblies by opening the context menu in Test Runner (see below)

    https://docs.unity3d.com/Packages/c...1.0/manual/workflow-create-playmode-test.html


    However, I can't find the same command in my Test Runner's context menu (see below). Is this a glitch/bug with unity? I haven't been able to find much online.

    upload_2021-3-19_15-16-21.png

    Thanks!
     
    fnnbrr, dan_ginovker and shochet like this.
  2. seanbiganski

    seanbiganski

    Joined:
    Aug 17, 2016
    Posts:
    31
    Did you solve this? I'm experiencing the same.
     
  3. KaPow1

    KaPow1

    Joined:
    Jan 27, 2013
    Posts:
    9
    No, I ended up using assembly definitions and was never able to get the option to show up
     
  4. unity_VenomGameStudio

    unity_VenomGameStudio

    Joined:
    Apr 25, 2020
    Posts:
    1
    Did anyone solve this issue yet?
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    In later versions (as specified in the docs), you have to open the projectsettings.asset file and set "playModeTestRunnerEnabled:" to 1
     
  6. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    That seems to be explained on https://docs.unity3d.com/Packages/c...1.1/manual/workflow-create-playmode-test.html indeed, but in 2021 the behaviour is different:

    - Setting the flag manually in ProjectSettings.asset will only result in a popup saying "Disable playmode tests for all assemblies - You must restart the editor now."
    - If you don't close the editor and still try to access your game classes, it won't work. Right-clicking on the Test Runner tab won't show "Disable playmode tests for all assemblies" either. So Unity actually already force-disabled it.
    - After closing the editor, the flag will be auto-reverted to 0.

    Therefore, I couldn't enable playmode tests for all assemblies, and the only way to test game classes via direct access now seems to create custom assemblies for your game scripts (as recommended on the same page).
     
    akuno, fnnbrr and nickfourtimes like this.
  7. RaVen011

    RaVen011

    Joined:
    Oct 31, 2017
    Posts:
    3
    Can you show how you do it?
     
  8. nyna77

    nyna77

    Joined:
    Jun 6, 2013
    Posts:
    3
    Is there any update on that? I don't want to create assemblies for my files, since 3rd parties plugins doesn't always support them.

    I noticed same behavior as @huulong but in 2020.3.20f1 version.
     
  9. dan_ginovker

    dan_ginovker

    Joined:
    Jun 13, 2021
    Posts:
    76
    Creating assemblies in our game has been an immensely difficult process. Our git submodules need to reference packages installed through the Asset Store, so every assembly in every submodule needs to reference things outside the submodule, which completely breaks the point of assembly definitions. While in theory we could move packages into the submodules themselves, that's not possible with all the packages we have installed. Also, it's an absolutely ridiculous thing to consider.

    All we want is to be able to create Playmode tests that can reference things in the game. That's it. Why is Unity Technologies actively fighting this?
     
    fnnbrr, NatureSimsVR, cdr9042 and 4 others like this.
  10. tomkail_betterup

    tomkail_betterup

    Joined:
    Nov 17, 2021
    Posts:
    106
    We just wasted some time on this too.
    Could someone from Unity please change this help text to reflect the intended behaviour? It's very misleading!
    We're new to the Test Runner but it does seem a bit weird to make it so difficult to set up - I'm sure there are good reasons not to enable it for all assemblies but it's definitely the most beginner friendly way for it to work.
    In the meantime we're just not going to use this package - but we'd really like to! Hope this gets resolved.
    upload_2022-4-7_11-52-1.png
     
    akuno and dan_ginovker like this.
  11. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    151
    Wasted an entire day of getting this to work.
    To clarify, there's absolutely no way of accessing game code without using asmdefs?

    Sidenote, I've tried creating an asmdef file for the entire project (that would just mimic Assembly-CSharp) but 999+ compile errors started showing up.
    Tried to manually link up some stuff, but that process is extremely tedious, since you have to manually click on the + every time to add a single reference. Also, searching in project view with t:asmdef works, but there's no way you can just drop them all together on the asmdef references list (like you can with other inspectors).
     
  12. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    I've been using TestRunner for years (since 2017?) but in 2020/2021 I find it completly impossible to get fscking UnityEditor to run a single PlayMode test - Unity broke it, and put this shoddy excuse for bad code in place instead.

    Has anyone logged bugs on this? It seems it's been badly broken for the last couple of years (I'm suffering this now because moving from 2019 LTS to 2020/2021 LTS)
     
    akuno likes this.
  13. kurtiswoww

    kurtiswoww

    Joined:
    Oct 2, 2013
    Posts:
    16
    so im attempting to use pubnub, installed it and if "Enable Playmode Tests for All Assemblies" is missing, then I cannot use it at all?
     
  14. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    Update: I finally got it to work by manually editing the Unity configuration files OUTSIDE the UnityEditor - there's showstopper bugs in the Editor UI code that apparently no-one has been testing/fixing for a while. I went through and deleted options that looked suspicious, and (by reading config files from old versions of Unity - 2018 etc) second-guessed the stuff the Editor was tryig and failing to do.

    I submitted at least one easily reproducible bug, it's been 3 months and no response from Unity.

    I recommend finding someone else who's got unit tests working in the exact way you want, and asking them to send you a ZIP file of their Unity Project, then you can read the text files by hand and make changes until you can get it working in your project.
     
    akuno and cdr9042 like this.
  15. PrimePeter

    PrimePeter

    Joined:
    Oct 4, 2019
    Posts:
    7
    Same Problem here, simply want to test my Scripts in PlayMode.
    This is very frustrating, when there is something like TestRunner and you work yourself in how it works...to end up that you cant test your Scripts.
     
    dan_ginovker likes this.
  16. wilburie

    wilburie

    Joined:
    Aug 26, 2023
    Posts:
    1
    same problem trying to use pubnub. anyone find a fix yet?!
     
  17. highpockets

    highpockets

    Joined:
    Jan 17, 2013
    Posts:
    71
    This was frustrating. Needed to add [RequiresPlayMode] attribute:

    Code (CSharp):
    1. //For all tests in the class
    2.  
    3. [TestFixture]
    4. [RequiresPlayMode]
    5. public class TestClass
    6.  
    7. //Or individual tests
    8.  
    9. [UnityTest]
    10. [RequiresPlayMode]
    11. public IEnumerator Some_Test()
    12.