Visual studio extension - Creating unit test for method the suppose to run on the UI thread

Viewed 162

How can I create unit tests for a method that should run on UI Thread? For example: The method to test:

    public void MenuItemBeforeQueryStatus(object sender, EventArgs e)
    {
        ThreadHelper.ThrowIfNotOnUIThread();

        // Do something
    }

The test:

    [TestMethod]
    public void UnitTest()
    {
        // Arrange
        // Create Target

        // Act
        target.MenuItemBeforeQueryStatus(null, EventArgs.Empty);

        // Assert
    }

The exception:

System.Runtime.InteropServices.COMException: MenuItemBeforeQueryStatus must be called on the UI thread. For UWP projects, if you are using UI objects in test consider using [UITestMethod] attribute instead of [TestMethod] to execute test in UI thread.

Does UITestMethod relevant in my case? I don't use UWP, I develop an extension for visual studio.

How can I create a test for it?

0 Answers
Related