【问题标题】:Play2: How to do execute piece of code before each test using specs2Play2:如何使用 specs2 在每次测试之前执行一段代码
【发布时间】:2013-09-08 11:33:40
【问题描述】:

我有这个代码:

class AccountSpec extends Specification {


    def fakeApp = FakeApplication(additionalConfiguration = inMemoryDatabase())

    "Every account" should {

        "have a user" in running(fakeApp) {

            Account.create("Basic account", "username")
            ...
            etc...
        }
    }
}

如果我尝试运行这个规范,我会得到一个错误,因为没有用户名为“username”的用户。所以我想做的是:

def before = { createTestUser() }

我尝试了不同的方法,但还没有找到解决方案。

【问题讨论】:

    标签: scala playframework-2.0 specs2


    【解决方案1】:

    只是从这个 trait org.specs2.mutable.BeforeAfter 扩展而来,它带有 before 和 after 方法,实现它们,这里是文档的链接 docs

    【讨论】:

    猜你喜欢
    • 2014-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多