2012-07-17 39 views
4

我有幾個不同的特性實現,我想測試,而測試只使用特徵的方法特徵,所以看起來我應該能夠使用參數化測試。然而,specs2網站似乎沒有描述編寫參數化測試的簡單方法。最接近的是如何「共享實例」,但你仍然需要測試的每個組合編寫和測試代碼,在這裏我希望能夠指定:如何使用規格編寫參數化測試?

A.測試
B.類測試

這可以單獨指定,但會測試兩者的笛卡爾積。

回答

6

寫像一些事情:

trait TraitTest extends Specification { 
    val thingWithTrait: TraitWithVariousImplementations 

//TESTS GO HERE 

} 

class TestFoo extends TraitTest { 
    val thingWithTrait = new Foo 
} 

class TestBar extends TraitTest { 
    val thingWithTrait = new Bar 
} 
7

也不要忘記,你可以使用循環:

class MySpecification extends mutable.Specification { 
    Seq(new Foo, new Bar) foreach { tested => 
    "it should do this" >> { tested must doThis } 
    "it should do that" >> { tested must doThat } 
    } 
}