How to test UI document?

I’m trying to write play mode tests for my ui elements, but I when I load a UI document, rootVisualElement is null:

[Test]
public void CanSerializeComponentElements()
{
var puzzle = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/UI/Prefabs/TestDocument.prefab");
var root = puzzle.GetComponent<UIDocument>().rootVisualElement;
Assert.IsNotNull(root); // fails
}

The prefab as a UIDocument component with a Uxml visual tree asset assigned to it. How do I initialize this document?

I had to instantiate the prefab before the UIDocument loaded.

var prefab = AssetDatabase.LoadAssetAtPath(“Assets/UI/Prefabs/TestDocument.prefab”);
var go = Object.Instantiate(prefab);
var root = go.GetComponent().rootVisualElement;
Assert.IsNotNull(root);