如何开始Windows窗体的单元测试? [英] How to start unit testing for windows forms?
本文介绍了如何开始Windows窗体的单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一段具有安全上下文的代码。
现在我的问题是如何进行单元测试?这是一个Windows窗体。用C#编写。我创建了一个单元测试项目。我想知道我应该包括哪些课程以及如何进行。已使用datagridview显示项目
I have a block of code which has a security context.
Now my question is how do i go about unit testing this? This is a windows form. Written in C#. I have created a unit test project. I want to know what classes should i include and how to do them. Have used datagridview to display the items
private void btnsearch_Click(object sender, EventArgs e)
{
string lastname=null;
refreshgrid();
Regex pattern = new Regex("^[a-zA-Z'-]{1,30}$");
if (String.IsNullOrEmpty(txtlname.Text)) //Checks if the textbox is empty or not
{
toolStripStatusLabel1.Text= "Last name Required";
}
else if (pattern.IsMatch(txtlname.Text)) //Regex pattern matching is done here
{
lastname = txtlname.Text.ToUpper().Trim(); //Trims the before and after spaces
fetchPatientDetails(lastname);
}
else
{
toolStripStatusLabel1.Text = "Invalid Input";
}
}
private void GridOperations(object sender, DataGridViewCellEventArgs e)
{
int rowindex = e.RowIndex;
DataGridViewRow row = ((DataGridView)sender).Rows[rowindex];
string id = row.Cells[0].Value.ToString();
switch (((DataGridView)sender).Name)
{
case "dgvpatient":
hidereaction();
hideallergy();
lblencounter.Show();
string patientid = row.Cells[0].Value.ToString();
displayDetails(sender, id, 1, 2180508);
break;
case "dgvencounter":
hidereaction();
lblallergy.Show();
displayDetails(sender, id, 2, 2180509);
break;
case "dgvallergy":
lblreaction.Show();
displayDetails(sender, id, 3, 2180510);
break;
}
}
我的尝试:
我不知道如何继续。
因此我没有尝试任何东西
What I have tried:
I have no idea how to proceed.
Hence i have not tried anything
推荐答案
);
if ( String .IsNullOrEmpty(txtlname.Text)) // 检查文本框是否为空
{
toolStripStatusLabel1.Text = 姓氏必填;
}
else if (pattern.IsMatch(txtlname.Text)) // 正则表达式模式匹配在这里完成
{
lastname = txtlname.Text.ToUpper()。Trim(); // 修剪前后空格
fetchPatientDetails(lastname);
}
else
{
toolStripStatusLabel1.Text = 输入无效;
}
}
"); if (String.IsNullOrEmpty(txtlname.Text)) //Checks if the textbox is empty or not { toolStripStatusLabel1.Text= "Last name Required"; } else if (pattern.IsMatch(txtlname.Text)) //Regex pattern matching is done here { lastname = txtlname.Text.ToUpper().Trim(); //Trims the before and after spaces fetchPatientDetails(lastname); } else { toolStripStatusLabel1.Text = "Invalid Input"; } }
private void GridOperations(object sender, DataGridViewCellEventArgs e)
{
int rowindex = e.RowIndex;
DataGridViewRow row = ((DataGridView)sender).Rows[rowindex];
string id = row.Cells[0].Value.ToString();
switch (((DataGridView)sender).Name)
{
case "dgvpatient":
hidereaction();
hideallergy();
lblencounter.Show();
string patientid = row.Cells[0].Value.ToString();
displayDetails(sender, id, 1, 2180508);
break;
case "dgvencounter":
hidereaction();
lblallergy.Show();
displayDetails(sender, id, 2, 2180509);
break;
case "dgvallergy":
lblreaction.Show();
displayDetails(sender, id, 3, 2180510);
break;
}
}
我的尝试:
我不知道如何继续。
因此我没有尝试任何东西
What I have tried:
I have no idea how to proceed.
Hence i have not tried anything
为您的c#代码创建单元测试 [ ^ ]
这篇关于如何开始Windows窗体的单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文