Writing tests for UI Toolkit

Hello,

I am working on a plugin that heavily relies on UI Toolkit.

I have unit tests for non-UI part of the plugin, but I am not sure how do I write tests for UI Toolkit.

I was thinking about something like initialising a dummy window that with the UI and trying to verify that business logic works as intended.

Is there a library that would let me write such tests? If not, are there plans in making one?

Many thanks!

The dummy window is unfortunately the way to go. You could also do some tests using runtime UI in the game view using play mode tests.

Keep in mind that the tests will probably need a bit of work to behave the same at all screen scaling if you try to make the tests strict on the dimensions.

Hello! I was facing the same problem and I ended up doing the same thing as in the package com.unity.dt.app-ui. Every custom control or view tests inherit from a VisualElementTest base class which handle the setup of the UIDocument etc. They are PlayMode tests too. They also have a shared test that can take screenshots of the control for visual regression testing i think.