天天看點

.net測試學習--了解.net測試選項

1.建立基于測試簡單應用程式

   (1)啟動visual studio(有安裝c#的)

  (2)  選擇File|New project

 (3)建立一個C# project,名字和儲存路徑自己設定,假設取名test1

.net測試學習--了解.net測試選項

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

設定屬性如下:

對象 屬性 value
Button1 Test check
TextBox1 Text 空白

此時視窗如下:

.net測試學習--了解.net測試選項

(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;

此時代碼結構如下:

.net測試學習--了解.net測試選項

(7)編譯,debugging 或者使用F5

  如果沒有錯誤,此時應該如下

.net測試學習--了解.net測試選項

(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

如圖:

.net測試學習--了解.net測試選項

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

此時整體代碼如下:

.net測試學習--了解.net測試選項

(3)運作 程式F5或者使用Debug

.net測試學習--了解.net測試選項

轉載請注明出處:http://www.cnblogs.com/tobecrazy/

.net測試學習--了解.net測試選項

軟體測試交流QQ群:312937087

we are QA!