Reputation: 4766
I'm writing a WPF application using MVVM, so I'm overriding OnStartup in App to set the View's ViewModel. Soon, at work, definition of done will include 100% code coverage so I'm trying to get in habit now at home on my own projects. I can't figure out how to test this function:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
ViewModel.MainViewModel vm = new ViewModel.MainViewModel();
View.MainView v = new View.MainView();
v.DataContext = vm;
v.Show();
}
}
Upvotes: 1
Views: 465
Reputation: 6961
Nick, I would suggest that you feed this back to work. You've basically found a perfect example of why 100% coverage isn't usually a standard that most people adhere to. Personally I advise the companies I work for to be more pragmatic. There is a case of diminishing returns the further up the coverage % that you go, and certainly for UI applications you can save a lot of time by asking yourself, what will this actually test.
The code you have is going to show an application view window with a view model. You can use libraries such as White or WiPFlash to provide easy ways of confirming this, but then all you have realy done is to confirm that windows has done its job. Later on you might be testign that clicking a button results in a value being displayed in a textbox and this has more value, but can be just as easily simulated by calling the ViewModel commands and checkign the view model state afterwards.
It is your choice, and I recommend trying both out, but these days I exclude my View namespace from all coverage counting.
Upvotes: 2