I’m using Unity 2022.3.22 with Unity Test Framework 1.4.4.
I have a bunch of Play Mode tests and I’d like to do some initialization before each test run.
The initialization should only happen once each time “Run Selected” or “Run All” is clicked in the Editor and likewise only once each time a Play Mode test run is started from command line.
From my understanding there are not a lot of ways of doing that, in fact I only found one alternative and that is implementing ITestRunCallback and register it with TestRunCallback. Then I could put my init code inside ITestRunCallback.RunStarted(...).
Maybe there is a bug in UTF here though, because RunStarted(...) is never called for Play Mode tests (it works for Edit Mode tests though). RunFinished(...) works as expected but that’s no help in my case.
Am I on the right track here? Is ITestRunCallback the only way forward in this case, given that the bug is fixed? Is it in fact a bug?
This ICallbacks interface is in a UnityEditor namespace, so perhaps you simply don’t have that script active when entering playmode. This may depend on your assembly definition settings.
Check my implementation of ICallbacks here and corresponding .asmdef:
This works fine for me and I can’t remember it not working in playmode.
Hello. We did indeed refactor the code around RunStarted in PlayMode in 1.4.4. It is part of our effort to backport the wider set of refactorings done originally for the 2.0 preview/experiment of UTF.
I am however having trouble reproducing it. @krs-two could you please report the issue via “help → Report a bug” in the editor? Then our support team can help putting together a repo case, so we can be sure we got your case covered.
Thanks in advance