欢迎访问测试中国(www.testingcn.com),做测试的朋友请加QQ群:45598719

NUnit2.0详细使用方法<三>

上一篇 / 下一篇  2007-03-14 14:36:40 / 个人分类:测试精华

Category属性

 对于测试来说,你有的时候需要将之分类,此属性正好就是用来解决这个问题的。

 你可以选择你需要运行的测试类目录,也可以选择除了这些目录之外的测试都可以运行。在命令行环境里/include/exclude来实现。在GUI环境下,就更简单了,选择左边工作域里的Catagories Tab,选择AddRemove既可以了。

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

 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属性的界面

 

Explicit属性

本属性忽略一个testtest fixture<SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: 'Cour

TAG: 测试精华

 

评分:0

我来说两句

Open Toolbar