Search Unity

Unity Editor UI Automation / Mocking

Discussion in 'Testing & Automation' started by flip_the_unflappable, Dec 8, 2020.

  1. flip_the_unflappable

    flip_the_unflappable

    Joined:
    Jul 9, 2020
    Posts:
    11
    Howdy all!

    I am wondering if it is possible to make UI automation tests to test custom Editor Windows or Property Drawers within the Unity Editor.

    Lets say I am making a plugin with a custom window that has lots of UI components. Is there a way that I can test these programmatically? Similar to how one might automate UI testing for a web app?

    Thanks
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    With IMGUI: it's very very difficult, you have to get creative about it. If you mock the whole [Editor]GUI[Layout] API then you can create some tests that check things like "When showAdvancedControls is true then does it try to draw a button with this label", but beyond that, you're looking at doing stuff like talking directly to Windows APIs to send keyboard/mouse events, and making IMGUI render to textures for comparison to reference images. It's not fun.

    With UI Toolkit: it's more straightforward. You can retrieve specific UI elements from your VisualTree, synthesise events to send to them, and then inspect the resulting state of the tree.

    (Improving testability was one of the original design goals of UI Toolkit).
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Ouch. Speaking from experience?