Reputation: 3320
I have several different implementations of a trait that I would like to test, and the test only uses the method signatures of the trait, so it seems like I should be able to use parameterized tests. However, the specs2 website doesn't seem to describe a straightforward way of writing parameterized tests. The closest is how to "share examples" but you still need to write every combination of tests and tested code, where I want to be able to specify:
A. Tests
B. Classes to test
That can be specified separately, but will test the cartesian product of the two.
Upvotes: 4
Views: 2646
Reputation: 15557
Also don't forget that you can use for loops:
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 }
}
}
Upvotes: 8
Reputation: 2717
Write some thing like:
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
}
Upvotes: 6