• <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詳細使用方法(7)

    發表于:2011-05-08來源:不詳作者:領測軟件測試網采編點擊數: 標簽:
    Suite Attribute 1namespace NUnit.Tests 2{ 3using System; 4 using NUnit.Framework; 5 6 7 8 public class AllTests 9 { 10 [Suite] 11 public static TestSuite Suite 12 { 13 get 14 { 15 TestSuite suite = ne

      Suite Attribute

    1namespace NUnit.Tests
    2{
    3using System;
    4 using NUnit.Framework;
    5
    6
    7
    8 public class AllTests
    9 {
    10 [Suite]
    11 public static TestSuite Suite
    12 {
    13 get
    14 {
    15 TestSuite suite = new TestSuite("All Tests");
    16 suite.Add(new OneTestCase());
    17 suite.Add(new Assemblies.AssemblyTests());
    18 suite.Add(new AssertionTest());
    19 return suite;
    20 }
    21 }
    22 }
    23}
    24

      Category屬性

      對于測試來說,你有的時候需要將之分類,此屬性正好就是用來解決這個問題的。

      你可以選擇你需要運行的測試類目錄,也可以選擇除了這些目錄之外的測試都可以運行。在命令行環境里 /include 和/exclude來實現。在GUI環境下,就更簡單了,選擇左邊工作域里的Catagories Tab,選擇Add和Remove既可以了。

      在上面的例子上做了一些改善,代碼如下:

     

    1using System;
    2using NUnit.Framework;
    3
    4namespace NUnitQuickStart
    5{
    6 [TestFixture]
    7 public class NumersFixture
    8 {
    9 private int a;
    10 private int b;
    11 [SetUp]
    12 public void InitializeOperands()
    13 {
    14 a = 1;
    15 b = 2;
    16 }
    17
    18 [Test]
    19 [Category("Numbers")]
    20 public void AddTwoNumbers()
    21 {
    22 int sum=a+b;
    23 Assert.AreEqual(sum,3);
    24 }
    25
    26 [Test]
    27 [Category("Exception")]
    28 [ExpectedException(typeof(DivideByZeroException))]
    29 public void DivideByZero()
    30 {
    31 int zero = 0;
    32 int infinity = a/zero;
    33 Assert.Fail("Should have gotten an exception");
    34 }
    35 [Test]
    36 [Ignore("Multiplication is ignored")]
    37 [Category("Numbers")]
    38 public void MultiplyTwoNumbers()
    39 {
    40 int product = a * b;
    41 Assert.AreEqual(2, product);
    42 }
    43
    44 }
    45

      NUnit-GUI界面如圖5-2:

      圖5-2:使用Catagories屬性的界面

    原文轉自: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>