问题描述
我正在尝试使用MSTest为WPF应用程序中MainWindow
类中的方法编写单元测试.但是,出现以下异常:
I'm trying to use MSTest to write unit tests for methods in my MainWindow
class in my WPF application. However, I get the following exception:
在App.xaml
中包含的ResourceDictionary
中找到
verticalLineStyle
.我不需要这种样式来测试我要测试的方法,但是我无法超越.我只是在单元测试中创建MainWindow
的新实例,然后尝试在该实例上调用实例方法.当我尝试创建MainWindow
的实例时发生异常. MainWindow
被定义为public partial class MainWindow : Window
.
verticalLineStyle
is found in a ResourceDictionary
that is included in App.xaml
. I have no need of this style to test the method I'm trying to test, but I can't get past this. I'm just creating a new instance of MainWindow
in my unit test and trying to call an instance method on that. The exception occurs when I try to create the instance of MainWindow
. MainWindow
is defined as public partial class MainWindow : Window
.
如何摆脱这个错误? WPF应用程序中的Windows中是否有一些首选的单元测试方法?
How do I get rid of this error? Is there some preferred way of unit testing methods in windows in WPF applications?
推荐答案
Application.LoadComponent(
new Uri("/MyAppAssemblyName;component/App.xaml", UriKind.Relative));
这对我有帮助.
这篇关于WPF-XamlParseException当Window类中的单元测试方法时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!