Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Visual studio扩展-为假定在UI线程上运行的方法创建单元测试_C#_Unit Testing_Mstest_Visual Studio Extensions_Vsix - Fatal编程技术网

C# Visual studio扩展-为假定在UI线程上运行的方法创建单元测试

C# Visual studio扩展-为假定在UI线程上运行的方法创建单元测试,c#,unit-testing,mstest,visual-studio-extensions,vsix,C#,Unit Testing,Mstest,Visual Studio Extensions,Vsix,如何为应该在UI线程上运行的方法创建单元测试?例如: 测试方法: public void MenuItemBeforeQueryStatus(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); // Do something } 测试: [TestMethod] public void UnitTest() { //

如何为应该在UI线程上运行的方法创建单元测试?例如: 测试方法:

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

        // Do something
    }
测试:

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

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

        // Assert
    }
例外情况:

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.
UITestMethod
与我的情况相关吗?我不使用UWP,我为VisualStudio开发了一个扩展


如何为其创建测试?

您在
MenuItemBeforeQueryStatus
方法中有什么?是否有任何呼叫
调度程序
调度程序
计时器?在
STA
线程上运行测试可能会有帮助。UITestMethod与我的情况相关吗?你试过用它吗?如何为其创建测试?不要测试
MenuItemBeforeQueryStatus
而是
//做点什么
你在
MenuItemBeforeQueryStatus
方法中有什么?是否有任何呼叫
调度程序
调度程序
计时器?在
STA
线程上运行测试可能会有帮助。UITestMethod与我的情况相关吗?你试过用它吗?如何为其创建测试?不要测试
MenuItemBeforeQueryStatus
,而是
//做点什么