Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Automating Editor UI Tests

Discussion in 'Immediate Mode GUI (IMGUI)' started by Qubitz, Jan 8, 2019.

  1. Qubitz

    Qubitz

    Joined:
    Jan 27, 2017
    Posts:
    7
    TL;DR - Does Unity support or does Unity have plans to support Microsoft's UI Automation accessibility framework?

    I love writing Unity editor scripts, but find myself unable to test my editor UI in Unity's editor. A common approach is using computer vision to visually navigate UI tests, but many more experienced than myself will warn against this method. Using the Windows 10 SDK's Inspect.exe, it seems that Unity supports neither Microsoft's UI Automation nor the Microsoft Active Accessibility frameworks, blocking access to automate UI tests for engineers and screen readers for the disabled.

    How does the Unity QA team test editor UI internally and is there any good alternatives?
     
  2. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    592
    As Unity's UI is not based on WPF, I doubt that they will be capable of supporting MS UI Automation. As I'm not really sure what blind users would do with the unity editor, I question the benefit of supporting it for that purpose.

    For functionality apart from the UI, Unity has built-in unit testing utilities. Their future plans to move over to a retained mode system for editor UI will eventually make it easier to separate functionality from the UI.

    If you have the patience and desire, you could probably write an autohotkey script to automate certain actions.

    In the meantime, the good old fashioned "click on everything" approach is your best bet.
     
  3. Qubitz

    Qubitz

    Joined:
    Jan 27, 2017
    Posts:
    7
    Bummer, thanks for the response and info about the retained mode Madgvox. Looking forward to that. There has been a few Unity Feedback requests for screen readers for visually impaired devs, but I imagine even then it would be tough.
     
  4. AlekseiKorolev

    AlekseiKorolev

    Joined:
    Aug 29, 2018
    Posts:
    1
    Hey there,

    I'm pretty much in the same situation: I have a very sophisticated editor window which behaviour I would like to cover with unit tests.

    I see three major ways to do it:
    1) External software, as you people already discussed.
    2) Fake IMGUI events: looks promising, but I feel like there is a whole bunch of implications.
    3) Separate business logic from UI and cover only business logic: separating stuff is always a good idea, but it's quite tricky with the IMGUI. And, obviously, it isn't too good to have large fraction of the project untested.

    I'm going to tackle this issue in the next few weeks, but it would find it very cool if someone would share their experience/best practices about this matter.
     
  5. Qubitz

    Qubitz

    Joined:
    Jan 27, 2017
    Posts:
    7
    I have been experimenting with writing editor tests with Unity's new UIElements (retained mode) feature officially released in 2019.1 with great success. Obviously, not everyone can hop on the 2019 hype train, but it's very promising going forward and something to look at if you're reading this in the future.

    Because of the hierarchy system implemented by UIElements very similar to HTML, you can verify layouts, styles, and (still working on this) simulate inputs, all from code :D. Beware that it takes some creativity to get write access to protected members of internal Unity classes.