I m not using MVVM model for my WP7(C#) application. Now I want to test button2_click function from my unit testing code so that the code inside the button_click gets executed. Please let me know if there is any possibility of doing this.
private void button_Click(object sender, RoutedEventArgs e)
{
// Some code
}
sample code could be really helpful.
Thanks,
Mugu
In general, UI code is not a good target for unit testing, regardless of whether you are using MVVM or not. You can unit test that button click handler just by calling it directly from your test. If the handler is using
senderand expecting it to be a real button then you will have to work out the best approach to take, nobody can answer that without seeing your code.Where MVVM would help you in this instance is it would allow you to move the code to the view model, and expose it via a property that returns an
ICommandwhich you then bind to theCommandproperty of the button. By using this approach you can encapsulate the code you would otherwise have embedded in the UI code behind and easily reuse the code in other commands (i.e. menu options).