.net测试学习--理解.net测试选项

1.创建基于测试简单应用程序

   (1)启动visual studio(有安装c#的)

  (2)  选择File|New project

 (3)创建一个C# project,名字和保存路径自己设定,假设取名test1

(4)添加一个text控件和button控件

设置属性如下:

对象 属性 value
Button1 Test check
TextBox1 Text 空白

此时窗口如下:

(5) 双击设计器中的check按钮(之前添加的Button1)

添加如下代码:

 

            if (textBox1.Text.Equals(""))          //if text is null  show message enter PATH
                MessageBox.Show("Please enter your file PATH\n");                     
           
            else                                   // check if your file is exists
               
             {     
                  if (File.Exists(textBox1.Text))
                         MessageBox.Show(textBox1.Text + "\tis exists\n");
                      else
                         MessageBox.Show(textBox1.Text + "\tisn't exists\n");
}


(6)在代码文件开头添加,不要忘记在结尾加分号

Using System.IO;

此时代码结构如下:

(7)编译,debugging 或者使用F5

  如果没有错误,此时应该如下

         

(8) 测试

         a.不输入  会提示:Please enter your file PATH

   b. 输入不存在的路径 比如aa 输出aa isn't exists 反向测试

     c.输入c:\Windows\explorer.exe 输出 c:\Windows\explorer.exe is exists 正向测试

2.用控制台应用程序创建测试软件

控制台程序访问的三种基本数据流:标准输入,标准输出和标准错误

(1)创建工程 选择File|New Project,单击Console application,此时可以设置工程名字:test2

如图:

(2)添加代码

在开头添加 Using System.IO

在main函数内添加如下代码:

 Console.WriteLine("***************************************************");
            Console.WriteLine("Enter the file PATH,Enter Q/q to quit\n");
            Console.WriteLine("***************************************************");
            string strInput = "";
            while (!strInput.ToUpper().Equals("Q")) //only if enter Q/q then quit
            {
                strInput = Console.ReadLine();          //read the command line and put into strInput
                Console.WriteLine("your file name is:"+ strInput);
                if (File.Exists(strInput))
                {
                    Console.WriteLine(strInput+" File Exists:Test PASS");
                }
                else
                {
                    Console.WriteLine(strInput + " File doesn't Exists:Test FAIL");
                    Console.WriteLine("Enter the file PATH,Enter Q/q to quit\n");
}
}

此时整体代码如下:

(3)运行 程序F5或者使用Debug

posted @ 2013-08-27 17:42  to be crazy  阅读(2021)  评论(2编辑  收藏  举报