The dynamic data provider should run on the same context (UI Thead here) than the test itself.
[TestClass]
public class SomeTests
{
[TestMethod]
[RunsOnUIThread]
[DynamicData(nameof(GetTestsData), DynamicDataSourceType.Method)]
public Do_The_Tests(FrameworkElement element)
{
// Do something with the `element`
}
public IEnumerable<object[]> GetTestsData()
{
var stackPanel = new StackPanel();
stackPanel.Children.Add(new Border()); // WILL CRASH HERE
yield return [ stackPanel ];
}
}
The dynamic data provider should run on the same context (UI Thead here) than the test itself.