Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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. }