google搜索 51Testing站内搜索                    软件测试门户 | 软件测试培 训 | 文章资料精选 | 软件测试论坛 | 软件测试博客 | 测试招聘求职 
打印

[求助] 如何进行C#单元测试,急

本主题由 fishy 于 2008-5-7 10:03 移动

如何进行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)
        {
        }
    }

TOP





/// <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.");
        }

TOP

cool! Smart answer
心中有敌人,一切皆为你敌人
心中无敌者,无敌于天下!!!

TOP

 
当前时区 GMT+8, 现在时间是 2008-7-24 20:24Copyright(C)上海博为峰软件技术有限公司 2001-2007 电话:021-64471599-8017
当您在访问网站、论坛及博客过程中遇到问题时可发送email:webmaster@51testing.com或发送论坛短信至管理员风在吹