3.Category的用法:测试用例分组,看看下面的代码和结果清楚了
using System;
using System.Text;
using NUnit.Framework;
namespace NUnitTest
{
[TestFixture]
public class CaculatorTest
{
private Caculator cac;
private int a;
private int b;
/// <summary>
/// 声明为TestFixtureSetUp的方法将在所有选中的TestCase调用之前调用,通常用来初始化数据库连接
/// </summary>
[TestFixtureSetUp]
public void InitUtility()
{
Console.Write("Caculator Invoked!");
}
/// <summary>
/// 声明为TestFixtureTearDown的方法将在所有选中的TestCase调用之后调用,通常用来销毁数据库连接
/// </summary>
[TestFixtureTearDown]
public void DestroyUtility()
{
Console.Write("Caculator Destroy!");
}
[SetUp]
public void Init()
{
cac = new Caculator();
a = 10;
b = 2;
Console.Write("Data Init!");
}
[TearDown]
public void Destroy()
{
Console.Write("TestCase Destroy!");
}
[Test]
[Category("GroupA")]
public void TestAdd()
{
int result = cac.Add(a, b);
Assert.AreEqual(12, result);
}
[Test]
[Category("GroupA")]
public void TestMinus()
{
int result = cac.Substract(a, b);
Assert.AreEqual(8, result);
}
[Test]
[Category("GroupB")]
public void TestMultip()
{
int result = cac.Multip(a, b);
Assert.AreEqual(20, result);
}
[Test]
[Category("GroupB")]
public void TestDivide()
{
int result = cac.Divide(a, b);
Assert.AreEqual(5, result);
}
}
}
运行结果:
若选中Exclude these Category,运行结果