【发布时间】:2019-06-01 09:07:52
【问题描述】:
这里是 Scala 菜鸟。
我目前尝试使用 specs2 为基于 Play (Scala) 的 Web 应用程序创建功能测试。示例本身很简单,即:
class SignInSpec extends PlaySpecification {
// bring the workflow steps in scope and instrument browser with them
import utils.WorkflowSteps.AuthSteps
"An activated user".should {
"be able to sign in to the admin console" in new WithDbData(webDriver = WebDriverFactory(FIREFOX)) {
// this should be: browser.signIn(testData.manager)
// with the manager already persisted in the database
browser.signIn(Manager(None, "me@home.com", "12341234", "John", "Doe", List("admin")))
}
}
}
我想要实现的是为每个示例提供一组已定义的测试数据,其中一些已经保存在数据库中。因此,我需要围绕每个示例进行设置和拆卸方法,准备一个TestData 案例类,用适当的数据填充它并保留其中的一些数据,以便示例可以从定义的数据库状态开始。
最终,我想要一个插件机制,其中插件为一组示例定义测试数据(将其视为贷款模式的应用)。
到目前为止我做了什么:
- 我尝试使用
Around的一些风格,但我不知道如何将数据输入示例,因为我必须添加额外的返回值。 - 我尝试了 specs2 的 ForEach 上下文,但这与 Play 的 WithBrowser 冲突
- 我玩过隐式 val,但我还是不知道如何将隐式参数添加到使用
DelayedInit从构造函数转换为函数调用参数的块中
任何想法如何继续实现以下目标?
- 从使用单个参数
TestData调用示例的附加特征或类扩展规范或示例 - 这个额外的特征或类应该能够准备测试数据并保留其中的一部分
- 此附加特征或类应与
WithBrowser兼容
【问题讨论】:
标签: scala playframework functional-testing specs2