Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you write a parameterized test using specs?

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.

like image 363
nnythm Avatar asked Dec 13 '22 00:12

nnythm


1 Answers

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 }
  }
}
like image 72
Eric Avatar answered Jan 07 '23 00:01

Eric