Search Unity

Help Wanted Scene Testing

Discussion in 'Testing & Automation' started by GainfulSage, Oct 29, 2018.

  1. GainfulSage

    GainfulSage

    Joined:
    Apr 30, 2015
    Posts:
    38
    I'm trying to write some tests that involve opening a particular scene. I'm able to open the scene with no problem using SceneManager.LoadScene, but the tests always wind up leaving a scene asset ("InitTestSceneWithRandomNumbers") left over in the project when the test finishing running.

    Is there a particular protocol or steps I should be following to ensure that the tests clean up?

    I've tried changing SceneManager.GetActiveScene to use LoadSceneMode.Additive and then using SceneManager.UnloadSceneAsync to clear the scene, and while I can see the scene loading and unloading in the hierarchy in the Editor, the InitTestScene is still leftover after the test run.

    I'm running my tests via the Play Mode in the Test Runner. Unity 2018.2.13f1 on Mac OS X 10.14.

    I feel really close - everything is working except for the leftover asset.

    Is there some other approach I should be using?
     
  2. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    533
    Are you using DontDestroyOnLoad in any of your scripts?
     
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,234
    Can you share some simple code that demonstrates this issue?
    The randomly generated scene is created by the test runner AFAIK (when execution starts, it will generates this scene to start all tests within a fresh new scene).

    In some cases, i also saw that this "temp" scene gets saved inside the project, but i do not have any consistent reproduction scenario.

    Why is this such a big problem for you? you can always clean up after the test ends in case this causes any problems.
     
  4. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    4
    @GainfulSage I am seeing an "InitTestScene*" scene left behind after each test run as well. Did you ever figure out a way to prevent this? My only solution so far is to gitignore scene files at the root of Assets/ so I don't accidentally commit them, but that's not stopping these files from accumulating after every test run...
     
  5. GainfulSage

    GainfulSage

    Joined:
    Apr 30, 2015
    Posts:
    38
    Nope, never found a fix. I think some combination of .gitignore and/or using a cloud build that just... kind of ignores the garbage? ... is probably the only option right now. Unity automated testing certainly feels a bit undeveloped compared to the server-side stuff I'm used to. ;)
     
  6. tlmak0

    tlmak0

    Joined:
    Jan 2, 2019
    Posts:
    1
  7. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    We don't have any InitTestScene files left behind after our tests unless they fail... However, .gitignore'ing it is probably the best approach.