Nunti测试工具使用整理

论坛 期权论坛 脚本     
匿名技术用户   2020-12-29 02:17   108   0

1.资源下载:

2.DotNet中使用

先安装

建立类库项目

右键属性,选择调试

在调试中,选择启动外部程序,选择Nunit.exe

在调试中,选择工作目录

完成后,F5将启动Nunit程序

3.

[TestFixture]

用于声明测试类,条件为Public

[TestFixtureSetup]

用于声明测试方法,最先执行1次

[TestFixtureTearDown]

用于声明测试方法,最后执行1次

[Test]

用于声明测试方法,条件为Public

[Setup]

用于声明测试方法,对应于[Test]有多少[Test]就执行多少次,在每个[Test]执行前执行

[TearDown]

同上,在每个[Test]执行后执行

[Ingory("")]

用语忽略部分不需要测试的方法

public void InitializeOperands() {//...}类似于初始化

[Category("分组名")]用于对测试方法进行分组,方便于测试

4.相关代码

[TestFixture]
public class Nunit测试类 //Nunit测试的类必须是public类型的
{
public Nunit测试类() { }
private int a, b;
[SetUp]
public void InitializeOperands() //这个方法是Nunit固定的方法,必须记忆
{
a = 1;
b = 2;
}
[Test]
public void TestSum()
{
// int a = 1;//重复部分可,提取出来
//int b = 2;//
int sum = a + b;
Assert.AreEqual(sum,3);
}
[Test]
public void Multiply()
{
//int a = 1;//
//int b = 2;//
int result = a * b;
Assert.AreEqual(result, 2);
}
}

5.参考资料

http://hi.baidu.com/grayworm/blog/item/009616601bba2fd98db10da4.html

6.各种断言

http://hi.baidu.com/grayworm/blog/item/4e741d2caacad8ea8a1399a0.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP