Question

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.

Was it helpful?

Solution

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
}

OTHER TIPS

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 }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top