Search Unity

TestPlayerBuildModifier not applied in PlayMode when executed from Editor

Discussion in 'Testing & Automation' started by Julian_Gamble, Apr 10, 2020.

  1. Julian_Gamble

    Julian_Gamble

    Joined:
    Feb 26, 2020
    Posts:
    7
    Use case:
    • I would like to apply TestPlayerBuildModifier when a PlayMode test is executed within the context of the editor, that-is, not run as standalone
    • This should allow engineers to create as many test scenes as they want, and not have to implicitly add them to the editor build settings for the purpose of running it in their editor workflow

    This is highlighted by the differences in how the PlayerLauncher & PlaymodeLauncher behave (the former appears to apply the build options where the latter does not). Ideally we could reuse the TestPlayerBuildModifier override in this scenario, otherwise I'd have to implement some kind of IPrebuildSetup.

    Is this the guidance for this scenario? It just seems a bit strange to bifurcate the configuration of Playmode tests across the Editor & Standalone context.

    For reference;
    Code (CSharp):
    1. [assembly:TestPlayerBuildModifier(typeof(IncludeTestSceneInBuild))]
    2. public class IncludeTestSceneInBuild : ITestPlayerBuildModifier
    3. {
    4.     public BuildPlayerOptions ModifyOptions(BuildPlayerOptions playerOptions)
    5.     {
    6.         // Do incredible things
    7.         return playerOptions;
    8.     }
    9. }
    As implied, this is correctly executed under the 'Run in player' context (standalone on target platform), but not from the Editor context (as executed by double clicking on any PlayMode test in the TestRunner).

    I am aware that I can introduce a new menu item that exercises a static method that does all the setup necessary, I'm just hoping there is a way to inject such overriding logic such that the idiomatic workflow presented in the TestRunner window is maintained.

    UTF - 1.1.13
    Unity - 2019.3.0f6

    Cheers!
    Julian
    Sr. Systems Engineer
    Kabam
     
    Last edited: Apr 11, 2020
  2. Warnecke

    Warnecke

    Unity Technologies

    Joined:
    Nov 28, 2017
    Posts:
    92
    Hey. As you mention, IPrebuildSetup can be used as well and that is the recommended way of doing any asset or code changes before the run starts.
     
    liortal likes this.
  3. Julian_Gamble

    Julian_Gamble

    Joined:
    Feb 26, 2020
    Posts:
    7
    Thanks for the info Warnecke. Is there any reason why something like this approach wasn't also used in the Standalone build testing path?
     
  4. Warnecke

    Warnecke

    Unity Technologies

    Joined:
    Nov 28, 2017
    Posts:
    92
    The main reason is that the BuildPlayerOptions is not available in IPrebuildSetup. So you can think of TestPlayerBuildModifier as a specialized version of IPrebuildSetup for when running tests in a player. Code path wise, they both the TestPlayerBuildModifier and IPrebuildSetup is invoked around the same part of the build setup.
     
    Julian_Gamble likes this.