nny*_*thm 4 unit-testing scala parameterized-unit-test specs2
我有几个不同的特征实现,我想测试,测试只使用特征的方法签名,所以我似乎应该能够使用参数化测试.但是,specs2网站似乎没有描述编写参数化测试的简单方法.最接近的是如何"共享示例",但您仍然需要编写测试和测试代码的每个组合,我希望能够指定:
A.测试
B.要测试的类
这可以单独指定,但将测试两者的笛卡尔积.
另外请不要忘记您可以使用for循环:
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 }
}
}
Run Code Online (Sandbox Code Playgroud)
写一些像:
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
}
Run Code Online (Sandbox Code Playgroud)