标题: 如何进行C#单元测试,急 [打印本页] 作者: jinhao_3 时间: 2008-5-5 14:50 标题: 如何进行C#单元测试,急 请各位高手帮忙看看,如何进行C#单元测试?万分感谢~!
namespace 成绩管理系统
{
public partial class Form1 : Form
{
Boolean b = false;
string str1 = @"Data Source=.;Initial Catalog=StudentCj;Integrated Security=True"; //无密码建立连接SQL数据库对象
public Form1()
{
InitializeComponent();
this.skinEngine1.SkinFile = "MP10.ssk"; //皮肤
}
private void Form1_Load(object sender, EventArgs e) //窗体加载时清空文本中的值
{
textBox1.Text = "";
textBox2.Text = "";
}
private void select()
{
SqlConnection con = new SqlConnection(str1);
string sql = "select Name,passwd from Admin where Name='" + textBox1.Text + "' ";
SqlCommand com = new SqlCommand();
com.CommandText = sql;
com.Connection = con;
con.Open();
SqlDataReader ada = com.ExecuteReader();
if (ada.Read())
{
if (ada["passwd"].ToString().Trim() != textBox2.Text.Trim())
{
MessageBox.Show("密码不正确");
textBox2.Focus();
return;
}
else
{
con.Close();
b = true;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
select();
if (b)
{
Main lons1 = new Main();
lons1.Show();
this.Visible = false; //进入Main窗体时不显示Form1窗体
}
else
{
MessageBox.Show("用户名和密码不正确 ");
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close(); //关闭
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}作者: eastsurfer 时间: 2008-5-8 04:00
/// <summary>
///A test for pictureBox1_Click
///</summary>
[TestMethod()]
[DeploymentItem("WindowsFormsApplication1.exe")]
public void pictureBox1_ClickTest()
{
Form1_Accessor target = new Form1_Accessor(); // TODO: Initialize to an appropriate value
object sender = null; // TODO: Initialize to an appropriate value
EventArgs e = null; // TODO: Initialize to an appropriate value
target.pictureBox1_Click(sender, e);
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
/// <summary>
///A test for Form1_Load
///</summary>
[TestMethod()]
[DeploymentItem("WindowsFormsApplication1.exe")]
public void Form1_LoadTest()
{
Form1_Accessor target = new Form1_Accessor(); // TODO: Initialize to an appropriate value
object sender = null; // TODO: Initialize to an appropriate value
EventArgs e = null; // TODO: Initialize to an appropriate value
target.Form1_Load(sender, e);
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
/// <summary>
///A test for button2_Click
///</summary>
[TestMethod()]
[DeploymentItem("WindowsFormsApplication1.exe")]
public void button2_ClickTest()
{
Form1_Accessor target = new Form1_Accessor(); // TODO: Initialize to an appropriate value
object sender = null; // TODO: Initialize to an appropriate value
EventArgs e = null; // TODO: Initialize to an appropriate value
target.button2_Click(sender, e);
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
/// <summary>
///A test for button1_Click
///</summary>
[TestMethod()]
[DeploymentItem("WindowsFormsApplication1.exe")]
public void button1_ClickTest()
{
Form1_Accessor target = new Form1_Accessor(); // TODO: Initialize to an appropriate value
object sender = null; // TODO: Initialize to an appropriate value
EventArgs e = null; // TODO: Initialize to an appropriate value
target.button1_Click(sender, e);
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
/// <summary>
///A test for select
///</summary>
[TestMethod()]
[DeploymentItem("WindowsFormsApplication1.exe")]
public void selectTest()
{
Form1_Accessor target = new Form1_Accessor(); // TODO: Initialize to an appropriate value
target.select();
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}作者: yuandjing 时间: 2008-5-21 11:29
cool! Smart answer