C# NUnit测试启动WPF应用程序,但WPF只允许每个AppDomain有一个应用程序
我正在编写验收测试,以启动我的WPF应用程序,如下所示:C# NUnit测试启动WPF应用程序,但WPF只允许每个AppDomain有一个应用程序,c#,wpf,nunit,appdomain,C#,Wpf,Nunit,Appdomain,我正在编写验收测试,以启动我的WPF应用程序,如下所示: [TestCase("279")] [TestCase("281")] [TestCase("289")] public void StartAndInitializeSystemControl(string machineNumber) { application = new App(); systemControl = new SystemControl(appl
[TestCase("279")]
[TestCase("281")]
[TestCase("289")]
public void StartAndInitializeSystemControl(string machineNumber)
{
application = new App();
systemControl = new SystemControl(application, machineNumber);
application.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => ApplicationOnActivated(null, null)));
application.Run();
Assert.Pass();
}
我遗漏了不相关的部分。我在上面的代码中所做的是启动WPFApp
,使用Application.Run()启动App,执行一些操作并验证一些操作。都很好,很好用。当我开始添加测试用例时,情况开始恶化。当我添加测试用例时,我会为每个AppDomain启动多个WPF应用程序,这是不允许的
System.InvalidOperationException:不能创建多个
同一AppDomain中的System.Windows.Application实例
我怎样才能解决这个问题?我可以从AppDomain“清除”已启动的应用程序吗?我可以为每次启动的测试启动一个不同的AppDomain吗?我尝试为每个测试创建一个AppDomain,但没有成功。你能告诉我怎么做吗?