[翻譯]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

相關文章
相關標籤/搜索