我想使用以下函数定义我的测试(暂时忽略一些依赖项,例如它们位于底部的fixture1
等):
multiTest("my test name", fixture1) { case (x: Double, y: Int, z: String) =>
// test body
}
和multiTest
在我的基本自定义FunSpecLike
子类中定义为:
def multiTest(testName: String, fixture: FixtureTable)(fun: => Unit)(implicit pos: source.Position): Unit = {
val heading = fixture.heading
fixture.values.foreach { tuple =>
it(autoGenerateDesc(heading, tuple)) {
fun tuple // <<<<<< how can I pass the tuple to the definition above?
}
}
}
如何将元组推送到函数?
一些缺失的部分是:
case class FixtureTable(heading: Map[String, String], values: Seq[Any])
// tableFor generates the permutations of all paramater values
val fixture1 : FixtureTable = tableFor(
("x", List(1e-1, 1e-2)),
("y", List(1, 2, 3)),
("z", List("a", "b")))
答案 0 :(得分:1)
实际上,你不能。将multitest
更改为
def multiTest(testName: String, fixture: FixtureTable)(fun: Any => Unit)(implicit pos: source.Position): Unit = {
val heading = fixture.heading
fixture.values.foreach { tuple =>
it(autoGenerateDesc(heading, tuple)) {
fun(tuple)
}
}
}
甚至更好
case class FixtureTable[A](heading: Map[String, String], values: Seq[A])
def multiTest[A](testName: String, fixture: FixtureTable[A])(fun: A => Unit)(implicit pos: source.Position): Unit = {
val heading = fixture.heading
fixture.values.foreach { tuple =>
it(autoGenerateDesc(heading, tuple)) {
fun(tuple)
}
}
}
但是为这种情况编写tableFor
函数会更难。