I have to run the code inside of my button_Click method to do regression testing, but since the method is private, I can't simply call it from my regression testing assembly.
private void button_Click(object sender, EventArgs e){
//Does stuff
}
What is the best approach to take from here? I have two ideas:
- Put the contents of button_Click into a separate public method
- Make button_Click a public method
I'm leaning more towards option 1, as it helps create more separation between the UI and business logic. Maybe there's an even better way to solve this problem?
Addendum:
Ok, so here is a simple example where I use a "thin" UI layer. Am I understanding this correctly? The RefreshForms method is part of the forms code, but put into it's own method to keep the button_Click method as thin as possible.
Then, the QA code only tests the business logic, and all is well?
Form Code:
private void button_Click(object sender, EventArgs e){
int res = BusinessLogic.SquareIt(Convert.ToDouble(textBox1.Text));
RefreshForms(res);
}
public void RefreshForms(){
textBoxRes = res.ToString();
}
BusinessLogic Code:
public void SquareIt(double input){
return Math.Pow(input, 2);
}
QA Code:
[Test]
public void RunTest(){
Assert.AreEqual(BusinessLogic.SquareIt(3),9);
}