Search Unity

Setting up test game objects in code (play mode tests)

Discussion in 'Testing & Automation' started by liortal, Feb 26, 2020.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    If i'd like to set up a particular scenario made up of a few GameObjects and components attached to them.
    Usually, In "normal" scenarios used by the game, scenes are saved to disk with all GameObjects and components.

    In the test context, i could create new game objects and add components, but every component added at runtime will automatically trigger its life cycle methods (e.g: Awake, Start, etc) which is not really identical to how things work when playing the actual game.

    Is it possible to somehow set up such a scenario (instantiate game objects and components to set up a test) while still simulating how things work "for real" as closely as possible ?

    * I know i could save a "test scene" to disk and then load that for my test, but that feels a bit "dirty".
    Looking for other solutions, if possible :)
     
  2. Warnecke

    Warnecke

    Unity Technologies

    Joined:
    Nov 28, 2017
    Posts:
    92