Search Unity

Resolved Test Runner not running on PlayMode

Discussion in 'Testing & Automation' started by fwalkerCirca, Aug 1, 2018.

  1. fwalkerCirca

    fwalkerCirca

    Joined:
    Apr 10, 2017
    Posts:
    57
    I am new to test runner and Unit Testing. I am trying to run some test on our application.
    I opened up Test Runner and created a default Test case on Play Mode. No modifications from me. I try run all in the test runner window, it starts the application, but the tests do not seem to be executed. I don't get a fail or a green check mark. If I try right clicking on the test case and select Run I get:
    "InvalidOperationException: This cannot be used during play mode, please use SceneManager.CreateNewScene() instead."

    I tried the exact same default test case, no modifications on the Editor Mode and the tests run fine and I get a nice little check mark.

    Any thought or idea on what might be going on?

    I need to run the test in Play Mode.

    Thanks
     
  2. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    @fwalkerCirca Did you manage to figure out how to create and run tests using the Unity Test Runner? If you're still struggling with anything, please let us know. We are getting more involved with our community regarding Testing and Automation.
     
  3. AlexKhundar

    AlexKhundar

    Joined:
    Mar 14, 2017
    Posts:
    19
    @ElvisAlistar
    Again a few months between last message but I got the same issue : in Play Mode, test does not seem to execute and stay at the default grey circle. There's neither the fail or green check mark.
    Trying to reproduce on brand new project, I've noticed something, though. There's a difference, both project using 2019.2.2f1.

    On the two projects, I did the same thing :
    - Project is free from any Assembly, at least on the Assets folder or children of Assets.
    - I'm located on Assets folder.
    - I opened the Test Runner window.

    So, on a brand new project, Test Runner window looks like this :
    NewProject.PNG
    Notice the warning message about non editor test assemblies, and the impossibility to create Test Script right now. When I'm making Test Assembly Folder and basic test script inside this folder, everything works.

    On my actual project (which is pretty recent, btw), Test Runner window looks like this :
    OldProject.PNG
    No more warning message, and I can create Test Script "from nowhere". It would be directly in the Asset folder. Obviously, it does not work when I do that. But it does not work either if I'm making a new PlayMode Test Assembly Folder, with new assembly, and then create the Test Script inside.

    Well, I just noticed this window reacts differently on the different projects. I hope this can help to find the issue.

    If you need any other element, please le me know :)
     
  4. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    mahmoud93p likes this.
  5. AlexKhundar

    AlexKhundar

    Joined:
    Mar 14, 2017
    Posts:
    19
    You're right, the visual difference was because of that. I indeed changed some parameters in order to try to make the tests work. But it didn't work in one case or another anyway (playmode tests for all assemblies enabled/disabled).

    If this can help anyone, I actually found how to solve my issue. In our project, in order to simplify some tests, we have a system which automatically change scene in editor in some situations. This lead to automatically quit the "InitTestScene" to start one of our own scene. I guess the internal test runner system didn't like that, and the tests were never completed, nor the game automatically finished.
    Adding an exception to our own system worked very well, tests are now correctly executed !
     
    booferei likes this.
  6. mahmoud93p

    mahmoud93p

    Joined:
    Feb 11, 2015
    Posts:
    66
    thank you it is work
     
  7. MiguelKing

    MiguelKing

    Joined:
    Apr 28, 2015
    Posts:
    5
    Thank you for posting the solution! I had the same problem!