[翻译]NUnit---Range and Repeat Attributes(十五)

RangeAttribute (NUnit 2.5)

  Range特性用于为参数话测试方法的参数的值范围指定一个值,与Random特性一样,NUnit会将每个参数的值组合为一些了测试用例,所以如果为一个参数设定数据那么必须为所以参数设定数据。默认情况下,NUnit使用参数的数据组合所有可能的情形。同时,可以使用在方法的指定特性上进行更改。

  Range特性支持一下构造

public RangeAttribute( int from, int to );
public RangeAttribute( int from, int to, int step );
public RangeAttribute( long from, long to, long step );
public RangeAttribute( float from, float to, float step );
public RangeAttribute( double from, double to, double step );

Example

The following test will be executed nine times, as follows:

	MyTest(1, 0.2)
	MyTest(1, 0.4)
	MyTest(1, 0.6)
	MyTest(2, 0.2)
	MyTest(2, 0.4)
	MyTest(2, 0.6)
	MyTest(3, 0.2)
	MyTest(3, 0.4)
	MyTest(3, 0.6)
[Test]
public void MyTest(
    [Values(1,2,3) int x,
    [Range(0.2,0.6,0.2] double d)
{
    ...
}

See also...

  • ValuesAttribute
  • RandomAttribute
  • SequentialAttribute
  • CombinatorialAttribute
  • PairwiseAttribute

RepeatAttribute (NUnit 2.5)

  测试方法需要指定执行次数时可以使用Repeat特性来实现。如果其中一次失败,则未执行不会再执行,并且会报告为一个失败。

NOtes:

  1、目前不能在TestFixture或者测试套件(test Suite)中使用Repeat特性。只有蛋哥测试才能使用。

  2、由于参数化的测试方法代表一个测试套件,所以Repeat特性在修饰参数化测试方法时会被忽略。

原文地址:https://www.cnblogs.com/kim01/p/3463896.html