I am writing acceptance tests that start my WPF application as follows:
[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();
}
I left out irrelevant parts. What I do in the code above is start the WPF App
, start the App with Application.Run()
execute something and verify something. All good, works fine. Things start to go south when I start to add test cases. When I add test cases, I am starting more than one WPF App per AppDomain, which is not allowed.
System.InvalidOperationException : Cannot create more than one System.Windows.Application instance in the same AppDomain.
How can I solve this? Can I "clear" the started application from the AppDomain? Can I start a different AppDomain for every test I start?