C# Visual studio扩展-为假定在UI线程上运行的方法创建单元测试
如何为应该在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() { //
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
,而是//做点什么