• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 淺談NUnit單元測試方法小總結(2)

    發表于:2011-12-30來源:博客園作者:韓迎龍點擊數: 標簽:NUnit單元測試
    namespace NunitTest { //模擬測試堆棧,堆棧是數據結構里面的一種類型,后進先出,與之相反的是隊列,先進后出 public class MyStack { private int nextIndex; //放置的

      namespace NunitTest

      {

      //模擬測試堆棧,堆棧是數據結構里面的一種類型,后進先出,與之相反的是隊列,先進后出

      public class MyStack

      {

      private int nextIndex; //放置的是下一個下標在數組中的元素

      private string[] elements; //存放字符串數組

      public MyStack() //構造函數

      {

      elements = new string[100]; //假設數組只能存放100個元素

      nextIndex = 0; //下一個元素的索引

      }

      //定義堆棧的操作

      public void push(string element)

      {

      if (100 == this.nextIndex)

      {

      throw new Exception("數組越界異常");

      }

      elements[nextIndex++] = element; //往堆棧里面壓的下一個元素

      }

      public string Pop() //取出數組中的元素

      {

      if (0 == this.nextIndex)

      {

      throw new Exception("數組越界異常");

      }

      return elements[--nextIndex];

      }

      public void Delete(int n)

      {

      if (this.nextIndex - n < 0)

      {

      throw new Exception("數組越界異常");

      }

      nextIndex -= n; //

      }

      public string Top()

      {

      if (0 == this.nextIndex)

      {

      throw new Exception("數組越界異常");

      }

      return elements[nextIndex - 1];

      }

      public int Size()

      {

      return this.nextIndex;

      }

      }

      }

      測試上面的方法是否正確在MystackTest類中,代碼如下所示:

      namespace NunitTest

      {

      [TestFixture]

      public class MyStackTest

      {

      private MyStack mystack;

      [SetUp]

      public void Init()

      {

      mystack = new MyStack();

      }

      [Test]

      public void TestPush()

      {

      mystack.push("Hello World");

      string result = mystack.Pop();

      Assert.AreEqual("Hello World", result);

      }

      [Test]

      public void TestPush2()

      {

      for (int i = 0; i < 100; ++i)

      {

      mystack.push(i + "");

      }

      for (int i = 0; i < 100; ++i)

      {

      string result = mystack.Pop();

      Assert.AreEqual((99 - i) + "", result);

      }

      }

      [Test,ExpectedException]

      public void TestPush3()

      {

      for (int i = 0; i < 101; ++i)

      {

      mystack.push(i + "");

      }

      for (int i = 0; i < 100; ++i)

      {

      string result = mystack.Pop();

      Assert.AreEqual((100 - i) + "", result);

      }

      }

      [Test,ExpectedException]

      public void TestPop()

      {

      mystack.Pop();

      }

      [Test]

      public void TestPop2()

      {

      mystack.push("Hello");

      mystack.push("World");

      mystack.Pop();

      string result = mystack.Pop();

      Assert.AreEqual("Hello", result);

      }

      [Test]

      public void TestTop()

      {

      mystack.push("Hello World");

      string result = mystack.Top();

      Assert.AreEqual("Hello World", result);

      }

      [Test,ExpectedException]

      public void TestTop2()

      {

      mystack.Top();

      }

      [Test]

      public void TestDelete()

      {

      for (int i = 0; i < 10; i++)

      {

      mystack.push(i + "");

      }

      mystack.Delete(10);

      Assert.AreEqual(0, mystack.Size());

      }

      [Test,ExpectedException]

      public void TestDelete2()

      {

      for (int i = 0; i < 10; i++)

      {

      mystack.push(i + "");

      }

      mystack.Delete(11);

      }

      }

      }

      對數據庫增刪改查的一些測試

      (1).判斷數據庫的鏈接,新建connection類代碼如下:

      public class connection

      {

      public static SqlConnection GetConnection() //連接數據庫函數

      {

      string connString = "server=HYL-PC;database=Test;uid=sa;pwd=saa";

      SqlConnection connection = new SqlConnection(connString);

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>