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.

Bug TestResult TestMode is always 0 even for PlayMode tests

Discussion in 'Testing & Automation' started by Xarbrough, Oct 12, 2022.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,173
    I'm registering a class that implements ICallbacks to receive RunsTarted, TestStarted and RunFinished. Within those callbacks I would like to differentiate between EditMode and PlayMode tests. Conveniently, all of the Adaptor classes have the Test.TestMode property which seems like an easy way to retrieve the information.

    However, in my tests, the test mode is always reported as the value "0" (number zero), even when running PlayMode tests. The enum declaration defines value 0 for EditMode and value 2 for PlayMode. But no matter how I start the test run (via the test runner window or scripting), the value is always 0.

    Is this a bug or some limitation or is there some special setup I need to consider?
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,532
    I am not sure about the value you're getting (did you try checking the UTF source code ?)

    Are you starting your tests using the scripting API? in this case you are specifying which Filter you want to use (E.g: which tests to run - EditMode or PlayMode), did you try to reuse this information and pass it on to your ICallbacks implementation ?
     
  3. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,173
    Thanks anyway! I've reported this internally and it was deemed a bug that will be fixed in the future, sorry no issue id to share at the moment.

    Another possible workaround, in case anyone needs it: it's possible to traverse the entire hierarchy of tests and search for any test mode which is "PlayMode". If at least one is found, the entire suite was a PlayMode run, if none are found in children and parents, then it was EditMode.