欢迎访问测试中国(www.testingcn.com),做测试的朋友请加QQ群:45598719
NUnit2.0详细使用方法<三>
上一篇 /
下一篇 2007-03-14 14:36:40
/ 个人分类:测试精华
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属性的界面
Explicit属性
本属性忽略一个test和test fixture<SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: 'Cour
相关阅读:
- 外包测试需迈三道坎 (leaf840404, 2007-3-12)
- 测试报告编写指南 (leaf840404, 2007-3-12)
- 新手必看《自动化测试工具介绍LR篇》 (leaf840404, 2007-3-12)
- 新手必看《自动化测试工具介绍QTP篇》 (leaf840404, 2007-3-12)
- 软件测试,从零开始:测试新手入门必读 (leaf840404, 2007-3-12)
- 性能和容量规划 (leaf840404, 2007-3-12)
- 测试工具大全(各类测试工具简介) (leaf840404, 2007-3-13)
- NUnit2.0详细使用方法<一> (leaf840404, 2007-3-14)
- NUnit2.0详细使用方法<二> (leaf840404, 2007-3-14)
收藏
举报
TAG:
测试精华