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

RangeAttribute (NUnit 2.5)

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

  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:ui

	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特性来实现。若是其中一次失败,则未执行不会再执行,而且会报告为一个失败。spa

NOtes:code

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

  二、因为参数化的测试方法表明一个测试套件,因此Repeat特性在修饰参数化测试方法时会被忽略。it

相关文章
相关标签/搜索