通过 ScalaTest 以编程方式添加新测试
Programmatically adding new tests via ScalaTest
我有一组输入案例存储在一个文件中。
我希望每个案例都是一个特定的 scalatest "test",即在控制台中报告为单独的测试并单独失败。
不幸的是,实验和 Google 表明此功能可能不存在?
例如,这似乎是常见情况(为简单起见省略)
class MyTestingGoop extends FunSuite {
val input : Seq[SpecificTestCase] = ...
test("input data test") {
forAll(input) { case => ... }
}
//...
}
理想情况下,每个 case
作为单独的测试呈现。如何使用 ScalaTest 完成此操作?
你可以这样做:
class MyTestingGoop extends FunSuite {
val input : Seq[SpecificTestCase] = ...
forAll(input) {
test("testing input" + input) {
// do something with the test
}
}
}
唯一的限制是输入具有唯一的 toString。
基本上在 Funsuite 中调用测试会注册测试并稍后运行它,因此只要您的测试创建是作为 class 构造的一部分完成的并且每个测试都有一个唯一的字符串,您应该没问题。
我有一组输入案例存储在一个文件中。
我希望每个案例都是一个特定的 scalatest "test",即在控制台中报告为单独的测试并单独失败。
不幸的是,实验和 Google 表明此功能可能不存在?
例如,这似乎是常见情况(为简单起见省略)
class MyTestingGoop extends FunSuite {
val input : Seq[SpecificTestCase] = ...
test("input data test") {
forAll(input) { case => ... }
}
//...
}
理想情况下,每个 case
作为单独的测试呈现。如何使用 ScalaTest 完成此操作?
你可以这样做:
class MyTestingGoop extends FunSuite {
val input : Seq[SpecificTestCase] = ...
forAll(input) {
test("testing input" + input) {
// do something with the test
}
}
}
唯一的限制是输入具有唯一的 toString。
基本上在 Funsuite 中调用测试会注册测试并稍后运行它,因此只要您的测试创建是作为 class 构造的一部分完成的并且每个测试都有一个唯一的字符串,您应该没问题。