Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Resolved Play mode testing with ML Agents

Discussion in 'ML-Agents' started by StewedHarry, Jul 31, 2020.

  1. StewedHarry


    Jan 20, 2020
    I was trying to run some play-mode tests for a training scenario and encountered problems which I have subsequently solved. I am sharing here in case anyone else runs into the same issue.

    My tests are relatively simple - a training instance prefab is instantiated and then tests are conducted on it.

    Running consecutive tests (e.g. 'run all') would cause most of the tests to fail, whereas they would pass when run individually.

    I have been using the Academy.Instance.OnEnvironmentReset event system to set up the training environment. However, this was creating the unwanted behaviour above because it is a singleton, and some state from the previous tests was being left over and causing the subsequent tests to fail.

    This is fixed by adding a setup and teardown method to the test class which calls the Acedemy.Instance.Dispose method:

    Code (CSharp):
    1. [TearDown]
    2. public void TearDown()
    3. {
    4.      Academy.Instance.Dispose();
    5. }