C#閏年測試程式白盒測試 20150426

來源:互聯網
上載者:User

標籤:

  使用visual studio對C#程式進行簡單的單元測試。

  1. 測試步驟

     1). 建立閏年測試專案,編寫代碼

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace ConsoleApplication1 8 { 9     public class Program10     {11         static void Main(string[] args)12         {13 14         }15         public static bool leap = new bool();16         public static bool isLeapYear(int year)17         {18             if (year == 0 || year < 0)19                 return false;20             leap = false;21             if (year % 4 == 0)22                 leap = true;23             if (year % 100 == 0)24                 leap = false;25             if (year % 400 == 0)26                 leap = true;27             return leap;28 29         }30     }31 }

2).在項目解決方案管理器中建立測試專案並為項目添加引用

3).編寫測試代碼:

 1 using System; 2 using Microsoft.VisualStudio.TestTools.UnitTesting; 3  4 namespace UnitTestProject1 5 { 6     [TestClass] 7     public class UnitTest1 8     { 9         [TestMethod]10         public void TestMethod1()11         {12             Assert.AreEqual(ConsoleApplication1.Program.isLeapYear(2012), true );13         }14         [TestMethod]15         public void TestMethod2()16         {17             Assert.AreEqual(ConsoleApplication1.Program.isLeapYear(2000), true);18         }19         [TestMethod]20         public void TestMethod3()21         {22             Assert.AreEqual(ConsoleApplication1.Program.isLeapYear(2100), false);23         }24         [TestMethod]25         public void TestMethod4()26         {27             Assert.AreEqual(ConsoleApplication1.Program.isLeapYear(0), false);28         }29         [TestMethod]30         public void TestMethod5()31         {32             Assert.AreEqual(ConsoleApplication1.Program.isLeapYear(-4), false);33         }34 35     }36 }

4).開啟測試資源管理員,產生測試

5).運行測試

2.程式流程圖

3.基本路徑集

A.1,2,6

B.1,2,3,6

C.1,2,3,4,6

D.1,2,3,4,5,6

4.測試案例

編號

輸入用例

覆蓋等價類別

覆蓋路徑

期望結果

輸出結果

Test1

2012

1,2

B

True

True

Test2

2000

1,3,5

D

True

True

Test3

2100

1,5

C

False

False

Test4

0

4

A

False

False

Test5

-1

4

A

False

False

 

 

 

 

 

 

 

 

 

測試回合成功,沒有出現任何問題。

C#閏年測試程式白盒測試 20150426

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.