Search Unity

Dynamic tests cases from scene content

Discussion in 'Testing & Automation' started by rubeng, Apr 20, 2020.

  1. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    60
    Hi, we are making a turn based combat game and the benefits of having some kind of integration testing for combat rules, abilities, etc are being more obvious as time passes.

    We started by making small scenarios or testcases where we could manually reproduce issues, or leave everything prepared to cast an ability and see how it works, but we want to add some automation to be able to run at least a part of those test cases as automated tests.

    The structure that we have right now is, a Unity scene contains several related test cases.

    I am trying to add play mode tests for this, and using parametrized tests its obvious how to add a test for each scene, but I would like to dig deeper, and define a Unity testcase for each testcase inside the scenes

    The mapping would be

    Unity test fixture => scene
    Unity test case => one for each instance of a component in scene

    The logic of these testcases I would try to define using either components and gameobject (trigger ability, check unit is alive, check unit has modifiier, pass turn, etc) or using Lua like we do in our cinematics (lua using MoonSharp) to avoid having to create a c# class for each test.

    The only two ways of having the content of the scene define the testcases right now is by having some kind of metadata export on each scene save, and parametrize the testfixtures using that metadata, but that seems a lot of work with chance for desynch or having to manage carefully those metadata assets. Or by being able to use the test runner api to add tests dinamically once the scene is open.

    Thanks for any information

    Rubén Garat

    P.S. It would be great to have a dedicated channel for testing and build automation in the official Unity discord.
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Is this a "test" scene? e.g: a scene file you prepared specifically for testing, but is not part of your shipped game ?

    You could separate it into multiple scenes - one scene per test case.
    This is a simple workaround - now you can run each test in its own scene, and you you also get proper separation between the tests (which is a big advantage!)
     
  3. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    60
    It is a test scene, there are some advantages to keeping it together because they share some common stuff and usually they are related (for example all the skills for a hero are in the same scene), so you can right now play the scene, and restart as any of the tests.
    I could use multi scene to share the common stuff but I think it becomes a bit weirder to manage, trying to make the manual test cases as easy to create and maintain as possible is a prioriity that I don't want to compromise too much.